jbb158 2017-11-04 07:56 采纳率: 0%
浏览 758

【小白 用c语言写了一个链表,找不出来错】

#include
#include
typedef struct ListNode{
struct ListNode *next;
int data ;
}Node,*Pnode;
void init(Pnode Phead){
Phead = (Pnode)malloc(sizeof(Node));
Phead->next=NULL;
}
void rearinsert(Pnode Phead,int n,int a[]){
Pnode Prear,Pnew;
Prear=Phead;
for(int i=0;i Pnew = (Pnode)malloc(sizeof(Node));
Pnew->data= a[i];
Pnew->next=NULL;
Prear->next=Pnew;
Prear=Pnew;
}
}
void head_insert(Pnode Phead,int n,int a[]){
Pnode Pnew;
for(int i=0;i Pnew=(Pnode)malloc(sizeof(Node));
Pnew->data= a[i];
Pnew->next=Phead->next;
Phead->next=Pnew;
}
}
void display(Pnode list){
Pnode p=list->next;
while(p!=NULL){
printf("%d",p->data);
printf(" ");
p=p->next;
}
}
void destory(Pnode list){
Pnode p,pre;
p=pre=list;
while(pre!=NULL){
pre=p->next;
free(p);
p=pre;
}
free(pre);
}
int select(Pnode list ,int n){// 提取i号元素的数据
n=n-1;
Pnode p=list->next;
for(int i=0;i<=n;++i){
p=p->next;
}
return p->data;
}

void main(){
Pnode list;
int a[]={3,5,6,9};
int n=4;
init(list);
rearinsert(list,4,a);
display(list);
}

  • 写回答

1条回答

  • threenewbee 2017-11-04 16:04
    关注

    首先,运行程序,测试它,看有什么不对。如果无法编译,根据编译器报错找到出错的行。
    运行程序出错的话,你的程序有好几个函数,比如插入、显示、查找等等,总能找到出错的函数吧。
    然后调试这个函数,看哪一步骤不对。
    就算你实在找不到哪里错,也请你做完上面三步以后再提问!

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办