list_pointer ptr=NULL; list_pointer node, trail; list_pointer *p=&ptr; int choose, location, i; printf("you should create a link first:/n"); //建立一个单向链表 prt=create () ; / *ptr指向链表的第一个节点* / print (ptr); //根据用户的不同选择进行相应的操作 printf("input number 0, you can quit the program/n"); printf("input number 1, you can insert a new node to link/n"); printf("input number 2, you can delete a node from the link/n"); printf("input number 3, you can invert the link/n"); printf("please input you choice/n"); scanf ("%d", &choose); while (choose!=0) switch (choose) case 1: i=1; while (i<looation) node=node->link; i++;
insert (p, node) ; /*p为指向ptr的指针*/ print (ptr); break; case 2: printf("you will delete a node from the link/n"); printf("please input the location of the node:/n"); scanf ("%d", &location) ; node=ptr; if (location==1) trail=NULL; trail=ptr; i=1; while (i<location) trail=trail->link; i++;
node=trail->link; delete_node (p, trail, node); print (ptr); break; case 3: printf("you will invert the link/n"); ptr=invert (ptr); print (ptr); break; default: break; return -1;
printf("please input you choice/n"); scanf ("%d", &choose);
int i, current, length; list_pointer p1, p2, head; printf("please input the node number of the link:/n"); scanf ("%d", &length) ; printf("the number of the link is:%d",length); printf("please input the data for the link node:/n"); i=0; p1=p2=(list_pointer)malloc(sizeof(list_node)) ; head=p1; for(i=1;i<length;i++) scanf ("%d", &current) ; p1->data=current ; p2->link=p1; p2=p1; p1=(list_pointer)malloc(sizeof(list_node));