Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- log_bin
- REACT
- java
- spring cloud
- JavaScript
- Webpack
- migration
- regex
- update
- Node
- Regular expression
- Effective Java
- log4j2
- npm
- 퀵소트
- Express
- Spring Batch
- spring
- REACTJS
- mysql 5.5
- upgrade
- MySQL
- 정규표현식
- eslint
- Chunk
- nodejs
- expire_logs_days
- current_date
- git
- Effective Java 3/e
Archives
- Today
- Total
내 세상
[Algorithms] Datastructure Queue 구현-Linked List 본문
728x90
반응형
#ifndef NULL
#define NULL 0
#endif
const int SIZE = 100010;
struct Node{
int num;
Node* next;
Node() : num(0), next(NULL) {}
Node(int n, Node* np){
num = n, next = np;
}
~Node() {
delete next;
}
void erase(Node*& ref){
ref = next;
next = NULL;
delete this;
}
}buf[SIZE];
int bcnt;
struct Queue{
Node*head, *tail;
int cnt;
Queue(){
cnt = 0;
head = tail = new Node();
}
~Queue(){
cnt = 0;
delete head;
head = tail = NULL;
}
}que;
Queue* newQueue(){
return new Queue();
}
void delQueue(Queue*que){
delete que;
}
bool empty(Queue*que){
return que->cnt == 0;
}
int size(Queue*que){
return que -> cnt;
}
int front(Queue*que){
return que->head->num;
}
int back(Queue*que){
return que->tail->num;
}
void push(Queue*que, int num){
que->cnt++;
que->tail->next = new Node(num, NULL);
que->tail = que->tail->next;
}
void pop(Queue*que){
if (empty(que)) return;
que->cnt--;
que->head->erase(que->head);
}
728x90
반응형
'Coding > Algorithms' 카테고리의 다른 글
[Algorithms] Hashtable / Probing / Hash Chaining / DJB2 (0) | 2021.03.12 |
---|---|
[Algorithms] Double Linked List 구현 (0) | 2021.03.10 |
[Algorithms] Disjoint sets (0) | 2021.02.26 |
[Algorithms] Merge Sort (0) | 2021.02.19 |
내꺼비공개 (0) | 2020.09.16 |