#include <stdio.h>
#include <stdlib.h>
typedef struct {
int data;
struct Node *prev;
struct Node *next;
} Node;
Node *head, *tail;
void insert(int data) {
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
Node* cur;
cur = head->next;
while (cur->data < data && cur != tail) {
cur = cur->next;
}
Node* prev = cur->prev;
prev->next = node;
node->prev = prev;
cur->prev = node;
node->next = cur;
}
void removeFront() {
Node* node = head->next;
head->next = node->next;
Node* next = node->next;
next->prev = head;
free(node);
}
void show() {
Node* cur = head->next;
while (cur != tail) {
printf("%d \n", cur->data);
cur = cur->next;
}
}
int main(void) {
head = (Node*)malloc(sizeof(Node));
tail = (Node*)malloc(sizeof(Node));
head->prev = head;
head->next = tail;
tail->prev = head;
tail->next = tail;
insert(4);
insert(9);
insert(3);
insert(1);
insert(8);
insert(7);
insert(6);
insert(2);
removeFront();
show();
system("pause");
return 0;
}
be the happy Gosu.
woojja ))*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
반응형
'ETC > C, C++' 카테고리의 다른 글
[C, C++] Counting Sort (2) | 2022.02.09 |
---|---|
[C, C++] Selection Sort, Insertion Sort (0) | 2021.11.04 |
[C, C++] Queue in Array, Linked List (0) | 2021.10.20 |
[C, C++] Stack in Array, Lined List (0) | 2021.10.20 |