Question
1. Add the following operation to the class orderedLinkedList: void mergeLists(orderedLinkedList &list1, orderedLinkedList &list2); //This function creates a new list by merging the //elements of
1. Add the following operation to the class orderedLinkedList:
void mergeLists(orderedLinkedList &list1, orderedLinkedList &list2);
//This function creates a new list by merging the //elements of list1 and list2.
//Postcondition: first points to the merged list
// list1 and list2 are empty
Consider the following statements:
orderedLinkedList newList;
orderedLinkedList list1;
orderedLinkedList list2;
Suppose list1 points to the list with the elements 2 6 7, and list2 points to the list with the elements 3 5 8. The statement
newList.mergeLists(list1, list2);
creates a new linked list with the elements in the order 2 3 5 6 7 8, and the object newList points to this list. Also, after the preceding statement executes, list1 and list2 are empty.
2. Write the definition of the function template mergeLists to implement the operation mergeLists.
Could anyone supply the main in C++?
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