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
- C언어
- queue
- 라인트레이서
- 아두이노 소스
- set
- Stack
- 아두이노 컴파일러
- arduino compiler
- 자료구조
- map
- Arduino
- 통계학
- vector
- 컴퓨터 그래픽스
- list
- 운영체제
- Algorithm
- Deque
- 시스템프로그래밍
- WinAPI
- 아두이노
- 수광 소자
- html
- priority_queue
- Visual Micro
- directx
- stl
- Array
- LineTracer
- c++
Archives
- Today
- Total
Kim's Programming
[C++/템플릿으로 만드는 자료구조] 단순원형연결리스트(Circular Linked List) 본문
Programming/Data Structure
[C++/템플릿으로 만드는 자료구조] 단순원형연결리스트(Circular Linked List)
Programmer. 2016. 1. 18. 21:06단순원형연결리스트의 소스입니다. 사용시에는 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | template<typename Type> class Node { public: Type VALUE; Node<Type> *Link; }; template<typename Type> class List { private: Node<Type> *header; Node<Type> *tailer; public: List(); ~List(); void Add_First(Type Item); void Add(int Position, Type Item); Type Delete(int Position); void Replace(int Position, Type Item); void Find(Type Item); void Get_Entry(int Position); void Get_Length(); bool Is_Empty(); void printing(); }; template<typename Type> List<Type>::List() { this->header = NULL; this->tailer = NULL; } template<typename Type> List<Type>::~List() { } template<typename Type> void List<Type>::Add_First(Type Item) { Node<Type> *New = new Node<Type>;//새로 값을 넣을 곳 if (this->header == NULL) { this->header = New; this->tailer = New; New->VALUE = Item; New->Link = this->tailer; return; } if (this->header != NULL) { New->Link = this->header; New->VALUE = Item; this->header = New; this->tailer->Link = this->header; return; } } template<typename Type> void List<Type>::Add(int Position, Type Item) { if (Position == 1 || this->header == NULL) { this->Add_First(Item); return; } int pos = 1; Node<Type> *Cur = this->header; Node<Type> *New = new Node<Type>; while (pos > Position - 1) { Cur = Cur->Link; pos++; } New->VALUE = Item; New->Link = Cur->Link; Cur->Link = New; } template<typename Type> Type List<Type>::Delete(int Position) { if (this->Is_Empty()) { return 0; } int pos = 1; int Retuen_Value; Node<Type> *Temp = NULL; Node<Type> *Cur = this->header; while (pos < Position) { if (Cur->Link == NULL) { std::cout << "NO data int this Position" << std::endl; return 0; } if (pos == Position - 1) Temp = Cur; Cur = Cur->Link; pos++; } Retuen_Value = Cur->VALUE; Temp->Link = Cur->Link; delete(Cur); return Retuen_Value; } template<typename Type> void List<Type>::Replace(int Position, Type Item) { int pos = 1; Node<Type> *Cur = this->header; while (pos < Position) { Cur = Cur->Link; pos++; } Cur->VALUE = Item; } template<typename Type> void List<Type>::Find(Type Item) { Node<Type> *Cur = this->header; int i = 1; while (Cur != this->header) { if (Cur->VALUE == Item) { std::cout << Item << " is in " << i << "(th) Node" << std::endl; } i++; Cur = Cur->Link; } if (Cur == NULL) { std::cout << Item << " is not in this List" << std::endl; } } template<typename Type> void List<Type>::Get_Entry(int Position) { int pos = 1; Node<Type> *Cur = this->header; while (pos < Position) { Cur = Cur->Link; pos++; } std::cout << Cur->VALUE << " is in " << Position << "(th) node" << std::endl; } template<typename Type> void List<Type>::Get_Length() { Node<Type> *Cur = this->header; int i = 1; while (Cur != this->header) { i++; Cur = Cur->Link; } std::cout << "this List has " << i << " Nodes" << std::endl; } template<typename Type> bool List<Type>::Is_Empty() { if (this->header == NULL) { std::cout << "This List is empty" << std::endl; return true; } std::cout << "This List is not empty" << std::endl; return false; } template<typename Type> void List<Type>::printing() { Node<Type> *Cur = this->header; std::cout << Cur->VALUE << " -> " << std::endl; Cur = Cur->Link; while (Cur != this->header) { std::cout << Cur->VALUE << " -> " << std::endl; Cur = Cur->Link; } std::cout << std::endl; } | cs |
같이보기
'Programming > Data Structure' 카테고리의 다른 글
[C++/템플릿으로 만드는 자료구조] 스택(Stack) (0) | 2016.01.18 |
---|---|
[C++/템플릿으로 만드는 자료구조] 이중연결원형리스트(Doubly Circular Linked List) (0) | 2016.01.18 |
[C++/템플릿으로 만드는 자료구조] 단순연결리스트(Linked List) (1) | 2016.01.18 |
[C로 만드는 자료구조]이진 탐색 트리(Binary Search Tree) (16) | 2015.12.25 |
[C로 만드는 자료구조]우선순위 큐(Priority Queue) (2) | 2015.12.18 |