자료구조 링크드 리스트....
진짜 링크드 리스트 하기 싫었는데 결국 했습니다....
하.....
<<소스코드>>
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct List
{
int data;
struct List* next;
}LIST;
typedef struct List* PLIST;
void Add ( PLIST plist );
void Delete();
void show();
PLIST head=NULL, tail=NULL;
void main()
{
int select;
PLIST plist;
while(1)
{
printf("SELECT!!\n");
printf("1. Intsert\n");
printf("2. Delete\n");
printf("3. Show\n");
printf("4. Exit\n");
printf("입력 : ");
scanf("%d",&select);
plist=(PLIST)malloc(sizeof(LIST));
switch(select)
{
case 1:
Add(plist);
break;
case 2:
Delete();
break;
case 3:
show();
break;
case 4:
exit(0);
}
}
free(plist);
}
void Add ( PLIST plist )
{
int num;
printf("넣을값:");
scanf("%d",&num);
plist->next=NULL;
plist->data=num;
if(head==NULL)// head가 NULL일때,
{
head=tail=plist;
}
else
{
tail->next=plist;
tail=plist;
}
}
void show()
{
PLIST plist=head;
while(plist)
{
printf("%d\n",plist->data);
plist=plist->next;
}
}
void Delete()
{
int num;
PLIST plist=head->next;
tail=head;
printf("삭제할값:");
scanf("%d",&num);
while(plist!=NULL)
{
if(plist->data==num)
{
tail->next=plist->next;
return ;
}
else
{
tail=tail->next;
plist=plist->next;
}
}
}