고수님들 꼭 좀 도와주세요,ㅠ6시간째 잡고있는데 정말 답답하네요,,ㅠㅠ부탁드려요
늘빈
1.순서대로 삽입하는 함수
2. 순차적으로 프린트 하는 함수
3.역으로 프린트하는 함수
4.임의의 숫자를 주고 그 숫자가 list안에 있는지 확인하는 함수
5.가장작은수를 밝히는 함수
6.가장큰수를 밝히는 함수
7.프린트 하는 시점에서, 현재까지 list에 있는 수를 모두 프린트하는 함수
(반드시 이중연결리스트를 이용)
위에 일곱개 함수를 넣어서 프로그램을 만든느건데요,,,일단 제가 만든 insert함수가 순서대로 삽입하는게 맞는지 잘 모르겠구요,또 제가 짠프로그램은 숫자를 작은수부터 큰수로입력하면 출력이 다 되는데 작은수에서 큰 수를 삽입하면 출력이 안되고요....ㅠㅠㅠ올림차순은 출력이 되는데 내림차순은 안되요,ㅠㅠ그리고 4,5,6,번함수도 부탁드릴께요!꼭좀 도와주세요,ㅠㅠㅠㅠㅠ
#include stdio.h
#include stdlib.h
////////////////////////////
typedef struct dnode
{
int data;
struct dnode* prev;
struct dnode* next;
}DNODE;
////////////////////////////
DNODE* head = NULL;
DNODE* tail = NULL;
DNODE* current;
////////////////////////////
void insert();
void print();
void printup();
void printdown();
void del_data();
////////////////////////////
void main()
{
int num;
while(1)
{
printf(*********** P r i n t *************\n\n);
printf(1. 입 력\n);
printf(2. 출 력\n);
printf(3. 올림차순출력\n);
printf(4. 내림차순출력\n);
printf(5. 검 색\n);
printf(6. 종 료\n\n\n);
printf(Chose index [ ]\b\b);
scanf(%d, &num);
switch(num)
{
case 1 : insert(); break;
case 2 : print(); break;
case 3 : printdown(); break;
case 4 : printup(); break;
case 5 : del_data(); break;
case 6 : exit(1); break;
}
}
}
////////////입 력 함 수/////////////
void insert()
{
DNODE* newnode;
newnode = (DNODE*)malloc(sizeof(DNODE));
printf( Put number : );
scanf(%d, &newnode-data); fflush(stdin);
newnode-next = NULL;
newnode-prev = NULL;
if( head == NULL )
{
head = newnode;
tail = head;
return;
}
if( tail-data newnode-data )
{
while(tail-prev != NULL)
{
if(tail-prev-data newnode-data)
{
newnode-next = tail;
newnode-prev = tail-prev;
tail-prev-next = newnode;
tail-prev = newnode;
tail = newnode;
return;
}
tail = tail-prev;
}
newnode-next = tail;
tail-prev = newnode;
head = newnode;
tail = newnode;
return;
}else
{
while(tail-next != NULL)
{
if(tail-next-data newnode-data)
{
newnode-next = tail-next;
newnode-prev = tail;
tail-next-prev = newnode;
tail-next = newnode;
tail = newnode;
return;
}else
tail = tail-next;
}
newnode-prev = tail;
tail-next = newnode;
tail = newnode;
return;
}
}
void print()
{
current = head;
while(current != tail-next){ //현재노드가 꼬리노드가 아닐때까지 루프를 돌림.
printf(%d ,current-data);
current = current-next;
}
printf(\n);
};
void printdown(){
DNODE* cur_print;
cur_print = head;
if(cur_print == NULL)
{
printf(Program has No data\n);
return;
}
printf(****올림차순****\n);
while(cur_print-next != NULL)
{
printf( %d - ,cur_print-data);
cur_print = cur_print-next;
}
printf( %d \n,cur_print-data);
}
void printup(){
DNODE* cur_print;
cur_print = head;
printf(***내림차순***\n);
while(cur_print-prev != NULL)
{
printf( %d - , cur_print-data);
cur_print = cur_print-prev;
}
printf( %d \n, cur_print-data);
}
void del_data()
{
int del_num;
DNODE* del;
if(head == NULL)
{
printf(program has No data\n);
return;
}
printf(Delete Num : );
scanf(%d, &del_num); fflush(stdin);
if( tail-data == del_num)
{
if( (tail-next==NULL) && (tail-prev==NULL) )
{
head=NULL;
del = tail;
tail = NULL;
free(del);
return;
}else if( tail-prev == NULL )
{
head = tail-next;
tail-next-prev = NULL;
del = tail;
tail = head;
free(del);
return;
}else if( tail-next == NULL)
{
tail-prev-next = NULL;
del=tail;
tail = tail-prev;
free(del);
return;
}else
{
tail-prev-next = tail-next;
tail-next-prev = tail-prev;
del=tail;
tail=tail-prev;
free(del);
&n);
return;
}
}else if( tail-data del_num)
{
while(tail-prev != NULL)
{
if(tail-prev-data == del_num)
{
tail-prev = tail-prev-prev;
tail-prev-prev-next = tail;
del = tail;
tail = tail-prev;
free(del);
return;
}
tail = tail-prev;
}
if(tail-data == del_num)
{
tail-next = head;
tail-next-prev = NULL;
del = tail;
tail = tail-next;
free(del);
return;
}
printf(Not found !!);
return;
}else
{
while(tail-next != NULL)
{
if(tail-next-data == del_num)
{
tail-next = tail-next-next;
tail-next-next-prev = tail;
del = tail;
tail = tail-next;
free(del);
return;
}
tail = tail-next;
}
if(tail-data == del_num)
{
tail-prev-next = NULL;
del = tail;
tail = tail-prev;
free(del);
return;
}
printf(Not found !!);
return;
}
}