Question
It is to assume that in this we have: struct Node { int data; Node *pNext; }; and in main we have: Node *pHead =
It is to assume that in this we have:
struct Node { int data; Node *pNext;
}; and in main we have:
Node *pHead = NULL; // pointer to the head of the list
Node *pTemp;// Used to get new nodes
Node *pHeadA = NULL;
Node *pHeadB = NULL;
The Code to create the list will be provided. Also the code to traverse and display the list elements will be provided. You can also assume that lists being processed already exist, and that the pointers for new lists are initialized to NULL. For the examples below, unless specified otherwise assume the list we are starting with is the list:
2->3->5->6->8->9->11
- Traverse a list, creating two new lists: one with all the even values, and the other with all the odd values.
The function header would be: evenOddLists( Node *pOriginal, Node *&pHeadEven, Node *&pHeadOdd) Assume the list we are starting with is the list:2->3->5->6->8->9->11
Calling evenOddLists(...)from within main would look like the following:
evenOddLists( pHead, pHeadA, pHeadB);
displayList( pHeadA);displayList( pHeadB); and it would result in the following output:
2->6->8
3->5->9->11
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started