C程序链表问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 18:00:46
帮忙看看下面代码里哪里错了,为什么尾结点删不掉??
还有如果要删中间的结点应怎么样改??谢谢

#include "stdio.h"
#include "conio.h"
#include "math.h"
#define null 0

struct id
{ int num;
char name[10];
struct id *next;
};

struct id *input()
{ struct id *a,*b,*c;
b=c=(struct id *)malloc(sizeof(struct id));
b->next=c->next=null;
printf("input num and id:");
scanf("%d,%s",&c->num,c->name);
a=null;
while(c->num!=0)
{ if(a==null) a=c;
else
{ b->next=c;
c->next=null;
b=c;
}
c=(struct id *)malloc(sizeof(struct id));
printf("input num and id:");
scanf("%d,%s",&c->num,c->name);
}
return(a);
}

void print(struct id *head)
{ do
{ printf("%d %s\n",head->num,he

看一看我怎么删这个链表的,应该对你有启发
#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
linklist *head;
linklist *hrear_creat()//建立链表
{
int x;
linklist *head,*p,*rear;
head=(struct node*)malloc(20);
head->data=-999;
rear=head;
//clear();
printf("请输入互不相同的正整数以0结束:\n\t");
scanf("%d",&x);
while(x!=0)
{
p=(struct node*)malloc(20);
p->data=x;
rear->next=p;
rear=p;
scanf("%d",&x);
}
rear->next=NULL;
return(head);
}
linklist *key_delete(linklist *head)
{
void print(linklist *rb);
linklist *p,*q;
int x,y,i;
printf("请输入要删除的起始结点:\n\t");
scanf("%d",&x);
printf("请输入要删除结点的个数:\n\t");
scanf("%d",&y);