일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 이진탐색
- Dijkstra
- MYSQL
- 그래프
- binary search
- Trie
- DP
- String
- Brute Force
- Hash
- 스토어드 프로시저
- Two Points
- SQL
- Stored Procedure
- 다익스트라
- two pointer
- union find
Archives
- Today
- Total
codingfarm
list(static allocation) 본문
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 | #include<iostream> using namespace std; class ListNode { public: int value; ListNode* pPrev, * pNext; ListNode() { value = -1; pPrev = 0; pNext = 0; } }; ListNode listNodePool[100000]; int listNodePoolIndex; ListNode* NewListNode() { int tmp = listNodePoolIndex; listNodePoolIndex++; listNodePool[tmp].value = -1; listNodePool[tmp].pPrev = nullptr; listNodePool[tmp].pNext = nullptr; return &listNodePool[tmp]; } class List { public: ListNode* front, * back; List() { _size = 0; front = NewListNode(); back = NewListNode(); front->pNext = back; back->pPrev = front; } void PushBack(int value) { ListNode* newNode = NewListNode(); newNode->value = value; ListNode* lastNode = back->pPrev; lastNode->pNext = newNode; back->pPrev = newNode; newNode->pPrev = lastNode; newNode->pNext = back; _size++; } void PushFront(int value) { ListNode* newNode = NewListNode(); newNode->value = value; ListNode* firstNode = front->pNext; firstNode->pPrev = newNode; front->pNext = newNode; newNode->pPrev = front; newNode->pNext = firstNode; _size++; } //prevNode 뒤쪽에 newValue를 추가한다. void Insert(ListNode* prevNode, int newValue) { ListNode* nextNode = prevNode->pNext; ListNode* newNode = NewListNode(); prevNode->pNext = newNode; nextNode->pPrev = newNode; newNode->pPrev = prevNode; newNode->pNext = nextNode; _size++; } ListNode* Erase(ListNode* deleteNode) { ListNode* prevNode = deleteNode->pPrev; ListNode* nextNode = deleteNode->pNext; prevNode->pNext = nextNode; nextNode->pPrev = prevNode; //delete deleteNode; _size--; return nextNode; } void Clear() { /* if(_size >= 1) { ListNode* it = front->pNext->pNext; for (; it != back; it = it->pNext) delete it->pPrev; delete it->pPrev; } */ front->pNext = back; back->pPrev = front; _size = 0; } int Size() { return _size; } ~List() { Clear(); //delete front; //delete back; } private: int _size; }; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); List list; for (int i = 10; i < 20; i++) list.PushBack(i); for (int i = 9; i >= 0; i--) list.PushFront(i); for (ListNode* it = list.front->pNext; it != list.back; it = it->pNext) cout << it->value << " "; return 0; } | cs |
'Algorithm & Data structure > 이론' 카테고리의 다른 글
Union Find (0) | 2020.09.06 |
---|---|
Merge Sort (0) | 2020.09.06 |
list(dynamic allocation) (0) | 2020.09.05 |
vector (0) | 2020.09.05 |
세그먼트 트리(Segment Tree) (0) | 2020.09.02 |
Comments