a. Add the following operation to the class orderedLinkedList:void mergeLists(orderedLinkedList<Type> &list1,orderedLinkedList<Type> &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 emptyConsider the following statements:orderedLinkedList<int> newList;orderedLinkedList<int> list1;orderedLinkedList<int> 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. b. Write the definition of the function template mergeLists to implement the operation mergeLists.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

a. Add the following operation to the class orderedLinkedList:
void mergeLists(orderedLinkedList<Type> &list1,
orderedLinkedList<Type> &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<int> newList;
orderedLinkedList<int> list1;
orderedLinkedList<int> 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.

b. Write the definition of the function template mergeLists to implement the operation mergeLists.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning