大家看看
我的这个单链表有什么问题,没有错误但就是运行出来的是那个调试程序的窗口,请大家帮忙看一下!#include<stdio.h>
#include<stdlib.h>
struct list{
int data;
struct list *next;
};
int ListIniticate(struct list *head){
struct list *p;
head=&p;
p=(struct list*)malloc(sizeof(struct list));
p->next=NULL;
}
int ListLength(struct list *head){
struct list *p=head;
int size=0;
while(p->next!=NULL){
p=p->next;
size++;
}
return size;
}
int ListInsert(struct list *head,int i,int x){
struct list *p,*q;
int j;
p=head;
j=-1;
while(p->next!=NULL&&j<i-1){
p=p->next;
j++;
}
if(j!=i-1){
printf("插入位置错误\n");
return 0;
}
else{
q=(struct list*)malloc(sizeof(struct list));
q->data=x;
q->next=p->next;
p->next=q;
return 1;
}
}
int ListDelete(struct list *head,int i,int *x){
struct list *p,*s;
int j;
p=head;
j=-1;
while(p->next!=NULL&&j<i-1&&p->next->next!=NULL){
p=p->next;
j++;
}
if(j!=i-1){
printf("删除位置错误\n");
return 0;
}
else{
s=p->next;
p->next=s->next;
free(s);
return 1;
}
}
int ListGet(struct list *head,int i,int *x){
int j;
struct list *p;
p=head;
j=-1;
while(p->next!=NULL&&j<i){
p=p->next;
j++;
}
if(j!=i){
printf("错误\n");
return 0;
}
else{
x=p;
*x=p->data;
return 1;
}
}
void main(void){
struct list *head;
int i,x;
ListIniticate(head);
for(i=0;i<10;i++)
ListInsert(head,i,i++);
ListDelete(head,4,&x);
for(i=0;i<ListLength(head);i++){
ListGet(head,i,&x);
printf("%4d",x);
}
}