Home > Back-end >  The list is divided into two lists
The list is divided into two lists

Time:09-29

Needs to be an odd number in the list in a list, even in a linked list, code attached, the result can't show, but the program did not collapse, how be to return a responsibility excuse me
 # include & lt; Iostream> 
# include "seqlist. H"
# include "time. H"
# include "stdlib. H"
using namespace std;

Int chaifeng (node * L, node * & amp; L1, node * & amp; L2) {
Node * (p1, p2, * u;
L1=new node;
L1 - & gt; Next=NULL;
P1=L1;
L2=new node;
L2 - & gt; Next=NULL;
The p2=L2;
The node * h=L - & gt; Next;
If (h==NULL | | h - & gt; Next==NULL) {//determine whether empty
return 0;
}
While (h!=NULL) {//circular linked list
If (h - & gt; Data % 2==0) {//to even
U=new node;
U - & gt; data=https://bbs.csdn.net/topics/h-> data;
U - & gt; Next=NULL;
P1 - & gt; Next=u;
P1=u;
H=h - & gt; Next;
} else {
U=new node;
U - & gt; data=https://bbs.csdn.net/topics/h-> data;
U - & gt; Next=NULL;
The p2 - & gt; Next=u;
The p2=u;
H=h - & gt; Next;
}
}
}

Int main (int arg c, char * argv [])
{
Node * L;
Node * L1.
Node * L2;
ElementType x;
CreateSCLLR (L);
If (chaifeng (L, L1, L2)!=0)
{
Cout<& lt;" Break up the successful "& lt; Cout<& lt;" Even table is: "& lt; PrintList (L1);
Cout<& lt;" Odd table is: "& lt; PrintList (L2);
}
}

CodePudding user response:

Chaifeng finally need a return value, the compiler didn't you call the police?
  • Related