请教一个问题 (删除一个元素)
#include <stdio.h>#include <stdlib.h>
typedef struct Lnode
{
int data;
struct Lnode *next;
}Lnode,*LinkList;
main()
{
LinkList h,p,q;
int i,num;
int n=10;
h=(LinkList)malloc(sizeof(Lnode));
p=q=h;
for(i=0;i<n;i++)
{
p=(LinkList)malloc(sizeof(Lnode));
scanf("%d",&p->data);
q->next=p;
q=p;
}
q->next=NULL;
printf("Please input the deleted number");
scanf("%d",&num);
p=h;
while(p->next&&p->next->data!=num)
{
//q=p;
p=p->next;
}
if(!p->next)
printf("Not found!");
else
{
p->next=p->next->next;
}
for(p=h;p->next!=NULL;p=p->next)
printf("%d",p->next->data);
}
[[it] 本帖最后由 liyanhong 于 2008-10-22 23:01 编辑 [/it]]