Question: Linked-List Write a program to read a series of positive integers from the user. The total number of input is unknown. Stop when the user
Linked-List
Write a program to read a series of positive integers from the user. The total number of input is unknown. Stop when the user supplies 0 or a negative number. Then output the series of numbers in reserve order.
For example, the input is 1 3 5 7 2 4 6 0, the output will be 6 4 2 7 5 3 1.
Hint: Store the input numbers in a linked-list.
main.cpp is given as
#include
int main() { ListElement* pList = NULL; int n; while (true) { cin >> n; if (n <= 0) break; pList = addFront(pList, n); } printList(pList); return 0; }
printList.cpp is given as
#include
listElement.h is given as
struct ListElement { int value; // value of an element ListElement* pNext; // Pointer to a list element };
Note:
You should not modify the contents of either main.cpp or printList.cpp.
All you need to do is preparing a .cpp file which contains the definition of the addFront() function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
