자료구조 3 -> 새그먼트 오류
#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* front = cur->prev;
front->next = node;
node->prev = front;
cur->prev = node;
node->next = cur;
}
void removeFront(){
Node *front = head->next;
head->next = front->next;
Node *newFront = front->next;
newFront->prev = head;
free(front);
}
void showAll(){
Node *cur = head->next;
while(cur != tail){
printf("%d ", cur->data);
cur = cur->next;
}
}
int main(void){
head = (Node*)malloc(sizeof(Node));
tail = (Node*)malloc(sizeof(Node));
head-> next = tail;
head-> prev = head;
tail-> next = tail;
tail-> prev = head;
insert(7);
insert(1);
insert(9);
insert(2);
insert(0);
insert(14);
removeFront();
showAll();
system("pause");
return 0;
}