#include <malloc.h>
typedef struct list_t
{
int id;
struct list_t *prior;
struct list_t *next;
}LIST;
void add_node(int n, LIST *p)
{
LIST *head, *pr, *pp;
int i;
pr = head; p = head->next;
while(p != NULL && p -> id < n) {
pr = p;
p = p -> next;
}
if((pp = (LIST *)malloc(sizeof(LIST))) == NULL) {
printf("Insertion is not success!");
} else {
pp -> id = n;
pp -> next = pr->next;
pr -> next = pp;
}
}
void remove_node(int id)
{
LIST * head, *p1, *p2;
int n;
if(head == NULL) {
printf("\nlist null !\n");
}
p1 = head;
while(id != p1 -> id && p1 -> next != NULL) {
p2 = p1;
p1 = p1 -> next;
}
if(id == p1 -> id) {
if(p1 == head) {
head = p1 -> next;
} else {
p2 -> next = p1 -> next;
printf("delete: %d\n", id);
n = n-1;
}
} else {
printf("%d not been found !\n", id);
}
}
int display(LIST *head)
{
int i = 0;
LIST *p;
p = head->next;
printf("Out the id : ");
while(p != NULL)
{
printf(" %d",p -> id);
i++;
p = p-> next;
}
printf("\n");
return (i);
}
void menu(void)
{
printf("\t\t\n");
printf("\t\t[A]Inserted the id !\n");
printf("\t\t[R]Delete the id !\n");
printf("\t\t[D]Display the id !\n");
printf("\t\t[Q]The program over !\n");
printf("\t\t\n");
printf("\t\t\n");
printf("\t\tPlease input your choose : A R D Q !\n");
}
int main(void)
{
int id;
int choose;
while(1)
menu();
scanf("%d",&choose);
switch(choose) {
case 'A':
printf("\nInput the inserted id %d", id);
scanf("%d",id);
add_node('A');
break;
case 'R':
printf("\nInput the delete id %d", id);
scanf("%d",id);
remove_node('R');
break;
case 'D':
printf("\nInput the display id %d", id);
scanf("%d",id);
display('R');
break;
case 'Q':
default:printf("ERROR!\n");
}
return 0;
}
有很多错误,功能也不能实现