#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct NODE* Head= NULL;
struct NODE* Temp= NULL;
struct NODE* Tail = NULL;
struct NODE
{
struct NODE* Llink;
char name[10];
char team[20];
struct NODE* Rlink;
};
void Add()
{
struct NODE* Data;
Data = (struct NODE*)malloc(sizeof(struct NODE));
Data->Llink = NULL;
Data->Rlink = NULL;
printf("Input Name : ");
scanf("%s", Data->name);
printf("Input Team : ");
scanf("%s", Data->team);
if(NULL == Head)
{
Head = Data;
Tail = Data;
return ;
}
else
{
Head->Llink = Data;
Data->Rlink = Head;
Head = Data;
return ;
}
}
void Delete()
{
struct NODE* LTemp;
struct NODE* RTemp;
char usertemp[10];
printf("What Delete Data :");
scanf("%s",usertemp);
if(0 == strcmp(usertemp,Head->name))
{
Head = Head->Rlink;
printf("Success\n");
return ;
}
Temp = Head;
while(1)
{
LTemp = Temp->Llink;
RTemp = Temp->Rlink;
if(NULL == RTemp && 0 == strcmp(usertemp,Temp->name ))
{
LTemp->Rlink=NULL;
printf("Success\n");
return ;
}
if(NULL == RTemp && 0 != strcmp(usertemp,Temp->name))
{
printf("No find\n");
return ;
}
if(0 == strcmp(usertemp,Temp->name))
{
LTemp->Rlink = RTemp;
RTemp->Llink = LTemp;
printf("Success\n");
return ;
}
Temp = Temp->Rlink;
}
}
void Show()
{
Temp = Head;
while(1)
{
if(NULL ==Temp)
{
printf("Not Data !\n");
return ;
}
printf("Name : %s Team : %s\n", Temp->name,Temp->team);
Temp = Temp->Rlink;
}
}
void ReverseShow()
{
Temp = Tail;
while(1)
{
if(NULL ==Temp)
{
printf("Not Data !\n");
return ;
}
printf("Name : %s Team : %s\n", Temp->name,Temp->team);
Temp = Temp->Llink;
}
}
int main(int argc, char** argv)
{
int key;
while(1)
{
printf("1 : Add 2. Delete 3. Show 4: Reverse Show \n");
scanf("%d",&key);
switch(key)
{
case 1:
Add();
break;
case 2:
Delete();
break;
case 3:
Show();
break;
case 4:
ReverseShow();
break;
default :
return 0;
}
}
return 0;
}