Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- set
- 시스템프로그래밍
- html
- 아두이노
- c++
- 아두이노 소스
- queue
- priority_queue
- Array
- Stack
- 아두이노 컴파일러
- 운영체제
- 수광 소자
- 라인트레이서
- Arduino
- C언어
- 컴퓨터 그래픽스
- LineTracer
- vector
- map
- WinAPI
- directx
- Visual Micro
- Deque
- stl
- 자료구조
- 통계학
- list
- arduino compiler
- Algorithm
Archives
- Today
- Total
Kim's Programming
[C++/템플릿으로 만드는 자료구조] 큐(Queue) 본문
C++/템플릿으로 제작한 큐(Queue)의 소스입니다. iostream을 인클루드 해야 이용할 수 있습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | template<typename Type> class Node { public: Node *Link; Type VALUE; }; template<typename Type> class Queue { private: Node<Type> *header;//제일 앞 포인터 Node<Type> *tailer;//제일 뒤 포인터 Node<Type> *pre_tail;//제일 뒤 바로 앞 포인터 public: Queue(); ~Queue(); bool Is_Empty(); void Enqueue(Type Item); Type Dequeue(); void Printing(); }; template<typename Type> Queue<Type>::Queue() { this->header = NULL; this->tailer = NULL; this->pre_tail = NULL; } template<typename Type> Queue<Type>::~Queue() { } template<typename Type> bool Queue<Type>::Is_Empty() { if (this->header == NULL) { std::cout << "This Queue is empty." << std::endl;; return true; } else { std::cout << "This Queue is not empty." << std::endl;; return false; } } template<typename Type> void Queue<Type>::Enqueue(Type Item) { Node<Type> *New = new Node<Type>; if (this->Is_Empty()) { this->header = New; this->tailer = New; New->VALUE = Item; New->Link = NULL; return; } else if (this->pre_tail == NULL) { New->Link = this->header; New->VALUE = Item; this->pre_tail = New; this->header = New; } else { New->Link = this->header; New->VALUE = Item; this->header = New; } } template<typename Type> Type Queue<Type>::Dequeue() { if (this->Is_Empty()) { return 0; } int Value = 0; Node<Type> *Temp = NULL; Node<Type> *Delete = NULL; Node<Type> *Cur = this->header; while (Cur != this->pre_tail) { Temp = Cur;//temp Tail 이전의 노드를 가리키는 포인터 저장 Cur = Cur->Link; } Delete = this->tailer; Value = Delete->VALUE; this->pre_tail = Temp; this->tailer = Temp->Link; this->tailer->Link = NULL; delete(Delete); return Value; } template<typename Type> void Queue<Type>::Printing() { Node<Type> *Cur = this->header; while (Cur != NULL) { std::cout << Cur->VALUE << " "; Cur = Cur->Link; } std::cout << std::endl; } | cs |
Queue는 STL에서 이용할 때는 queue를 인클루드 하여 사용하게됩니다.
같이보기
2015/12/16 - [Programming/자료구조] - [C로 만드는 자료구조]큐(Queue) - 배열
2015/12/16 - [Programming/자료구조] - [C로 만드는 자료구조]큐(Queue) - 동적
'Programming > Data Structure' 카테고리의 다른 글
[C++/템플릿으로 만드는 자료구조] 이진탐색트리(Binary Search Tree) (0) | 2016.01.18 |
---|---|
[C++/템플릿으로 만드는 자료구조] 덱(Deque) (0) | 2016.01.18 |
[C++/템플릿으로 만드는 자료구조] 스택(Stack) (0) | 2016.01.18 |
[C++/템플릿으로 만드는 자료구조] 이중연결원형리스트(Doubly Circular Linked List) (0) | 2016.01.18 |
[C++/템플릿으로 만드는 자료구조] 단순원형연결리스트(Circular Linked List) (0) | 2016.01.18 |