//1、不含头结点的链表实现
#include <stdio.h>
#include <stdlib.h>
#include "List.h"
int main()
{
struct node* head = NULL;
int a,x,position;
printf("1 for Insert,2 for delete:\n");
while(scanf("%d",&a))
{
if(a==1)
{
printf("Input the position and element:\n");
scanf("%d %d",&position,&x);
head=Insert(head,position,x);
Print(head);
}
else
{
printf("Input the element you want to delete:\n");
scanf("%d",&x);
head=DelNode(head,x);
Print(head);
}
printf("1 for Insert,2 for delete:\n");
}
return 0;
#include <stdio.h>
#include <stdlib.h>
#include "List2.h"
int main()
{
struct node* head = NULL;
int a,x,position;
head=InitialList(head);
printf("1 for Insert,2 for delete:\n");
while(scanf("%d",&a))
{
if(a==1)
{
printf("Input the position and element:\n");
scanf("%d %d",&position,&x);
head=Insert(head,position,x);
Print(head);
}
else
{
printf("Input the element you want to delete:\n");
scanf("%d",&x);
head=DelNode(head,x);
Print(head);
}
printf("1 for Insert,2 for delete:\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "List.h"
int main()
{
struct node* head = NULL;
int a,x,position;
printf("1 for Insert,2 for delete:\n");
while(scanf("%d",&a))
{
if(a==1)
{
printf("Input the position and element:\n");
scanf("%d %d",&position,&x);
head=Insert(head,position,x);
Print(head);
}
else
{
printf("Input the element you want to delete:\n");
scanf("%d",&x);
head=DelNode(head,x);
Print(head);
}
printf("1 for Insert,2 for delete:\n");
}
return 0;
}
//2、带有头结点的链表实现
#include <stdio.h>
#include <stdlib.h>
#include "List2.h"
int main()
{
struct node* head = NULL;
int a,x,position;
head=InitialList(head);
printf("1 for Insert,2 for delete:\n");
while(scanf("%d",&a))
{
if(a==1)
{
printf("Input the position and element:\n");
scanf("%d %d",&position,&x);
head=Insert(head,position,x);
Print(head);
}
else
{
printf("Input the element you want to delete:\n");
scanf("%d",&x);
head=DelNode(head,x);
Print(head);
}
printf("1 for Insert,2 for delete:\n");
}
return 0;
}