데이터 10개를 삽입하고 삭제하는 동작을 수행하는건데 컴파일 해보면 작동 중지됫다고 나오네요 ㅠㅠ
해결좀....
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int key;
char name[10];
char grade;
}element ;
typedef struct doubleListNode {
element data;
struct doubleListNode* rlink;
struct doubleListNode* llink;
} deqNode;
typedef struct {
deqNode* first;
deqNode* last;
int length;
} deque;
deque* createDeque() {
deque* deq;
deq = (deque *)malloc(sizeof(deque));
deq->first = NULL;
deq->last = NULL;
deq->length = 0;
return deq;
}
int isEmpty(deque* deq) {
if (deq->length == 0)
return 1;
else return 0;
}
void insertFirst(deque* deq, element item) {
deqNode* newNode;
newNode = (deqNode *)malloc(sizeof(deqNode));
newNode->data = item;
if (deq->length == 0) {
deq->first = newNode;
deq->last = newNode;
newNode->rlink = NULL;
newNode->llink = NULL;
}
else {
deq->first->llink = newNode;
newNode->rlink = deq->first;
newNode->llink = NULL;
deq->first = newNode;
}
deq->length++;
}
void insertLast(deque* deq, element item) {
deqNode* newNode;
newNode = (deqNode * )malloc(sizeof(deqNode));
newNode->data = item;
if (deq->length == 0) {
deq->first = newNode;
deq->last = newNode;
newNode->rlink = NULL;
newNode->llink = NULL;
}
else {
deq->last->rlink = newNode;
newNode->rlink = NULL;
newNode->llink = deq->last;
deq->last = newNode;
}
deq->length++;
}
element deleteFirst(deque* deq) {
deqNode* temp;
element item;
if(deq->length==0) {
printf("Deque is empty\n"); exit(1);
}
else {
item = deq->first->data;
temp = deq->first;
if (deq->first->rlink = NULL) {
deq->first = NULL; deq->last = NULL;
}
else {
deq->first = deq->first->rlink;
deq->first->llink = NULL;
}
deq->length--;
free(temp);
return item;
}
}
element deleteLast(deque* deq) {
deqNode* temp;
element item;
if (deq->length==0) {
printf("Deque is empty\n"); exit(1);
}
else {
item = deq->last->data;
temp = deq->last;
if (deq->last->llink = NULL) {
deq->first = NULL;
deq->last = NULL;
}
else {
deq->last = deq->last->llink;
deq->last->rlink = NULL;
}
deq->length--;
free(temp);
return item;
}
}
void removeFirst(deque* deq) {
deqNode* temp;
if (deq->length==0) {
printf("Deque is empty\n");
exit(1);
}
else {
temp = deq->first;
if (deq->first->rlink = NULL) {
deq->first = NULL;
deq->last = NULL;
}
else {
deq->first = deq->first->rlink;
deq->first->llink = NULL;
}
deq->length--;
free(temp); }
}
void removeLast(deque* deq) {
deqNode* temp;
if (deq->length==0) {
printf("Deque is empty\n");
exit(1);
}
else {
temp = deq->last;
if (deq->last->llink = NULL) {
deq->first = NULL;
deq->last = NULL;
}
else {
deq->last = deq->last->llink;
deq->last->rlink = NULL;
}
deq->length--;
free(temp);
}
}
element peekFirst(deque* deq) {
if (deq->length==0) {
printf("Deque is empty\n");
exit(1);
}
else return deq->first->data;
}
element peekLast(deque* deq) {
if (deq->length==0) {
printf("Deque is empty\n");
exit(1);
}
else return deq->last->data;
}
int main() {
element data1, data2, data3, data4, data5, data6, data7, data8, data9, data10;
deque* deq;
deq = createDeque();
data1.key = 1;
strcpy(data1.name, "Lee");
data1.grade = 'A';
data2.key = 2;
strcpy(data2.name, "Park");
data2.grade = 'B';
data3.key = 3;
strcpy(data3.name, "Jung");
data3.grade = 'C';
data4.key = 4;
strcpy(data4.name, "Kim");
data4.grade = 'D';
data5.key = 5;
strcpy(data5.name, "Ji");
data5.grade = 'E';
data6.key = 6;
strcpy(data6.name, "Yim");
data6.grade = 'F';
data7.key = 7;
strcpy(data7.name, "Jo");
data7.grade = 'G';
data8.key = 8;
strcpy(data8.name, "Shin");
data8.grade = 'H';
data9.key = 9;
strcpy(data9.name, "Joo");
data9.grade = 'I';
data10.key = 10;
strcpy(data10.name, "Lee");
data10.grade = 'J';
printf("push data1 : (%d, %s, %c)\n", data1.key, data1.name, data1.grade);
insertFirst(deq, data1);
printf("push data2 : (%d, %s, %c)\n", data2.key, data2.name, data2.grade);
insertLast(deq,data2);
printf("push data3 : (%d, %s, %c)\n", data3.key, data3.name, data3.grade);
insertFirst(deq, data1);
printf("push data4 : (%d, %s, %c)\n", data4.key, data4.name, data4.grade);
insertFirst(deq, data1);
printf("push data5 : (%d, %s, %c)\n", data5.key, data5.name, data5.grade);
insertLast(deq,data2);
printf("push data6 : (%d, %s, %c)\n", data6.key, data6.name, data6.grade);
insertLast(deq,data2);
printf("push data7 : (%d, %s, %c)\n", data7.key, data7.name, data7.grade);
insertLast(deq,data2);
printf("push data8 : (%d, %s, %c)\n", data8.key, data8.name, data8.grade);
insertFirst(deq, data1);
printf("push data9 : (%d, %s, %c)\n", data9.key, data9.name, data9.grade);
insertLast(deq,data2);
printf("push data10 : (%d, %s, %c)\n", data10.key, data10.name, data10.grade);
insertFirst(deq, data1);
removeFirst(deq);
removeLast(deq);
removeFirst(deq);
removeLast(deq);
removeFirst(deq);
removeLast(deq);
removeFirst(deq);
removeLast(deq);
removeFirst(deq);
removeLast(deq);
removeFirst(deq);
removeLast(deq);
}
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.