需要將鏈表中的奇數放在一個鏈表中,偶數放在一個鏈表中,代碼附上,結果無法顯示,但是程式沒有崩潰,請問是怎么回事
#include <iostream>
#include "seqlist.h"
#include "time.h"
#include "stdlib.h"
using namespace std;
int chaifeng(node *L, node *&L1, node *&L2){
node *p1,*p2,*u;
L1=new node;
L1->next=NULL;
p1=L1;
L2=new node;
L2->next=NULL;
p2=L2;
node *h=L->next;
if(h==NULL||h->next==NULL){ //判斷是否為空
return 0;
}
while(h!=NULL){ //回圈鏈表
if(h->data%2==0){ //是否為偶數
u=new node;
u->data=https://bbs.csdn.net/topics/h->data;
u->next=NULL;
p1->next=u;
p1=u;
h=h->next;
}else{
u=new node;
u->data=https://bbs.csdn.net/topics/h->data;
u->next=NULL;
p2->next=u;
p2=u;
h=h->next;
}
}
}
int main(int argc, char* argv[])
{
node *L;
node *L1;
node *L2;
elementType x;
createSCLLR(L);
if(chaifeng(L,L1,L2)!=0)
{
cout<<"拆分成功"<<endl;
cout<<"偶數表為:"<<endl;
printList(L1);
cout<<"奇數表為:"<<endl;
printList(L2);
}
}
uj5u.com熱心網友回復:
chaifeng最后需要一個回傳值,你編譯器竟然沒報警?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/95877.html
標籤:C++ 語言
上一篇:vs問題解決
下一篇:求助各位幫忙看看
