亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

鏈表中的段錯誤,幫忙找一下吧

鏈表中的段錯誤,幫忙找一下吧

C
weibo_殤雨916_0 2016-05-17 12:58:52
輸入一個正整數 repeat (0<repeat<10),做 repeat 次下列運算: 輸入若干個正整數(輸入-1為結束標志),建立一個單向鏈表,將其中的奇數值結點刪除后輸出#include<stdio.h> #include<stdlib.h> #include<string.h> typedef?struct?Node {? int?data; struct?Node?*next;? }No; No*?createlist() { ? No?*?head; ? No?*?p,*?pre; ? int?i,a; head=(No*)malloc(sizeof(No)); head->next=NULL; pre=head; while(scanf("%d",&a)) { if(a!=-1) ????{ p=(No*)malloc(sizeof(No)); ???? p->data=a; pre->next=p; pre=p; } else { pre->next=NULL; break; } ???}? ??return?head; } void?print(No*head) { int?i,n=0; No*?q=head; No*h=head->next; while(h) { if((h->data)%2!=0) { q->next=h->next; h=h->next; } else{ q=h; ???? h=h->next; } } free(h); while(head->next->next) { printf("%d?",head->next->data); head=head->next; } printf("%d",head->next->data); } int?main() { int?n,i; scanf("%d",&n); for(i=0;i<n;i++){ print(createlist()); printf("\n"); } return?0; }輸入樣例:2?(repeat=2) 1?2?3?4?5?6?7?-1 1?3?5?-1輸出樣例:2?4?6
查看完整描述

1 回答

?
杰倫窗外的小麻雀

TA貢獻16條經驗 獲得超7個贊


我本職做前端的,不要總是問我C啊,表示不會

查看完整回答
反對 回復 2016-05-17
  • 1 回答
  • 0 關注
  • 2351 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號