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 | 29 | 30 |
Tags
- java
- Chunk
- current_date
- Express
- mysql 5.5
- log4j2
- 정규표현식
- npm
- MySQL
- Spring Batch
- JavaScript
- git
- upgrade
- REACTJS
- Node
- nodejs
- Webpack
- migration
- eslint
- Effective Java 3/e
- spring
- REACT
- 퀵소트
- expire_logs_days
- log_bin
- Effective Java
- update
- spring cloud
- regex
- Regular expression
Archives
- Today
- Total
내 세상
[Algorithms] Double Linked List 구현 본문
728x90
/// === main.cpp ===
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
const int MAX_LEN = 1100000;
int N, bn;
struct Node {
char val;
Node* prev;
Node* next;
Node() : prev(NULL), next(NULL), val(0) {}
Node* alloc(char _val, Node *_prev, Node *_next){
val = _val;
prev = _prev;
next = _next;
return this;
}
}buf[MAX_LEN];
Node* Head;
Node* cursor;
void insert(char ch){
Node* temp = buf[bn++].alloc(ch, NULL, NULL);
temp->val = ch;
temp->next = cursor->next;
temp->prev = cursor;
if (cursor->next != NULL) cursor->next->prev = temp;
cursor->next = temp;
cursor = temp;
}
void leftMove(){
if (cursor->prev != NULL){
cursor = cursor->prev;
}
}
void rightMove(){
if (cursor->next != NULL){
cursor = cursor->next;
}
}
void remove(){
if (cursor->prev != NULL){
cursor->prev->next = cursor->next;
if (cursor->next != NULL) cursor->next->prev = cursor->prev;
cursor = cursor->prev;
}
}
char arr[MAX_LEN];
int main(){
//freopen("input.txt", "r", stdin);
scanf("%d", &N);
char t;
for (int T = 0; T < N; T++){
bn = 0;
cursor = buf[bn++].alloc(0, NULL, NULL);
Head = cursor;
for (int i = 0; i < MAX_LEN; i++) arr[i] = 0;
scanf("%s", &arr);
for (int i = 0; t = arr[i]; i++){
if (t == '<'){
leftMove();
}
else if (t == '>'){
rightMove();
}
else if (t == '-'){
remove();
}
else {
insert(t);
}
}
while (Head->next != NULL){
printf("%c", Head->next->val);
Head = Head->next;
}
printf("\n");
}
return 0;
}
728x90
'Coding > Algorithms' 카테고리의 다른 글
[Algorithms] 오름차순 데이터 저장 기반 double linked list (0) | 2021.03.21 |
---|---|
[Algorithms] Hashtable / Probing / Hash Chaining / DJB2 (0) | 2021.03.12 |
[Algorithms] Datastructure Queue 구현-Linked List (0) | 2021.03.10 |
[Algorithms] Disjoint sets (0) | 2021.02.26 |
[Algorithms] Merge Sort (0) | 2021.02.19 |