单链表删除操作求助
各位大神你们好!请大神帮忙看下:#include<stdio.h>
#include<malloc.h>
#define N 8
struct List
{
int data;
struct List *link;
}list;
//建立一个单链表
List *dlbj(int a[],int n)
{
List *s,*h;
int i;
h=(List *)malloc(sizeof(list));
h->data=0;
h->link=NULL;
for(i=n;i>0;i--)
{
s=(List *)malloc(sizeof(list));
s->data=a[i-1];
s->link=h->link;
h->link=s;
}
return h;
}
//删除函数
struct List *dlbsc(struct List *head,int Q)
{
struct List *p1,*p2;
while(head!=NULL)
{
p2=head;
head=head->link;
free(p2);
}
if(head==NULL)
return NULL;
p1=head;
p2=head->link;
while(p2!=NULL)
{
if(p2->data=Q)
{
p1->link=p2->link;
free(p2);
}
else
p1=p2;
p2=p1->link;
}
return head;
}
//主函数
void main()
{
int a[8]={1,2,11,21,6,5,56,44},n,i;
a[8]=8;
int dlbj(int i,int a[]);
List *h,*p;
printf("The original linklist is:\n");
for(n=0;n<=N;n++)
printf("%5d",a[n]);
printf("\n");
printf("Please enter the cancel position:\n");
scanf("%d",&i);
printf("After cancel the linklist is:\n");
for(n=0;n<=N-1;n++)
printf("%5d",a[n]);
printf("\n");
}
能调试,但运行不成功,不知道程序错在哪
小白不胜感激!!