#include "stdio.h"
#include "malloc.h"
#include "string.h"
#include "stdlib.h"
typedef struct stu
{
char name[10];
int no;
struct stu *next;
}* pstu,stu;
int main()
{
int i,a;
stu n;
pstu head,pnew,head1,p;
head = (pstu)malloc(sizeof(n));
if (head == NULL)
{
exit(-1);
}
head1 = head;
for (i = 0;i < 10;i++)
{
pnew = (pstu)malloc(sizeof(n));
head1->next = pnew;
pnew->next = NULL;
head1 = pnew;
}
s:printf("请输入的结点位置:");
scanf("%d",&a);
head1 = head->next;
for (i = 0;i < a;i++,head1 = head1->next){
if(head1 == NULL)
{
printf("%d",i);
if (i < a)
{
printf("没有该节点,请重新输入!!");
goto s;
}
}
}
pnew = head1->next;
p = (pstu)malloc(sizeof(stu));
strcpy(p->name,"cc1j");
p->no = 2211;
head1->next = p;
p->next = pnew;
head1 = head;
for (i = 1,head1 = head->next;i < 3;i++)
{
head1 = head1->next;
}
p = head1->next;
head1->next = p->next;
free(p);
return 0;
}刚忙去了,我试了一下,你看看