struct Link *InsertNode01(struct Link *head,int nodeData,int i)
{ int j=1;
struct Link *pr = head, *p, *temp = NULL;
p = (struct Link *)malloc(sizeof(struct Link));
if(p == NULL)
{
printf("NO enough memory");
exit(0);
}
p->next = NULL;//置新节点的指针域为空
p->data = nodeData;//为新节点赋数据域的值
if(head == NULL)//插入新节点前,对原链表的一个判断,不同情况插入的方法不同
{
head = p;
}
else
{ if(i = 1)
{
p->next = head;
head = p;
}
else
{ while(j < i && pr->next != NULL)
{
temp = pr;
pr = pr->next;
j++;
}
if(j = i)
{
pr = temp;
p->next = pr->next;
pr->next = p;
}
else
{
pr -> next = p;
}
}
}
return(head);
};
int main()
{
int i = 0;
int place = 0;
int nodeData;
char c;
struct Link *head = NULL;//指向链表头
printf("Do you want to append a new node(Y/N)");
scanf(" %c",&c);
while(c=='Y' || c=='y')
{
head = AppendNode(head);
DispLink(head);//显示当前各节点信息
printf("Do you want to append a new node(Y/N)");
scanf(" %c",&c);
i++;
}
printf("%d new nodes have been appended!\n",i);
printf("please input the nodeData you want to delete:");
scanf("%d",&nodeData);
DeleteNode(head,nodeData);
DispLink(head);
printf("please input the nodeData you want to insert:");
scanf("%d",&nodeData);
printf("输入插入的位置");
scanf("%d",&place);
InsertNode01(head,nodeData,place);
DispLink(head);
//InsertNode(head,nodeData);
//DeleteMemory(head);//释放分配内存
return 0;
}