4. C++ Write a Client function that merges two instances of the Sorted List ADT
ID: 3536969 • Letter: 4
Question
4. C++ Write a Client function that merges two instances of the Sorted List ADT using the following specification.
MergeLists(SortedType list1, Sortedtype list2, SortedType& result)
Function: Merge two sorted lists into a third sorted list.
Precondition: list1 and list2 have been initialized and are sorted by key using function ComparedTo.
Postcondition: result is a sorted list that contains all of the items from list1 and list2.
c. Write function the definition, using a linked based implementation.
d. Describe the algorithm in terms of Big-0
Explanation / Answer
void MergeLists(SortedType list1, SortedType list2, SortedType& result); void MergeLists(SortedType list1, SortedType list2, SortedType& result) { Int length1; Int length2; Int counter1 = 1; Int counter2 = 1; ItemType item1; ItemType item2; Length1 = list1.lengthIs(); Length2= List2.LengthIs(); List1.ResetList(); List2.resetList(); List1.GetNextItem(item1); List1.GetNextItem(item2); Result..MakeEmpty(); While( counter1Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.