
没有前导节点的链表问题

#include<stdio.h>
#include<stdlib.h>
typedef struct linknode
{
int data;
struct linknode *next;
} node;
node *Creat()
{
node *head,*p,*s;
int x,cycle=1;
printf("Please input total number of data item (press 0 end):");
head=(node* )malloc(sizeof(node));
head->next=NULL;
p=head;
while (cycle) {
scanf("%d",&x);
if (x!=0) {
s=(node*)malloc(sizeof(node));
s->data=x;
p->next=s;
p=s;
}
else cycle=0;
}
p->next=NULL;
p=head;
head=head->next;
free(p);
return head;
}
void Delet(node *head,int i)
{
int n=1;
node *p;
if (i==1){
p=head;
head=head->next;
free(p);
}
else{
while(head!=NULL){
if(i==n+1) break;
head=head->next;
n++;
}
head->next=head->next->next;
}
}
int main(void)
{
int a;
node *head,*p=NULL;
head=Creat();
printf("输入值a \n");
scanf("%d",&a);
Delet(head,a);
for(p=head;p!=NULL;p=p->next) printf("%d",p->data);
return 0;
}

在删除没有头节点的链表时,程序的第一个数字是如何删除头节点. 请请上帝帮助修改我的程序. 非常感谢.

||集合||
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-224712-1.html
我也会选择守护目前来之不易的生活
美国欺负到门上了