Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement SplitLists as a member function of the linked Sorted List ADT. Here is

ID: 3671496 • Letter: I

Question

Implement SplitLists as a member function of the linked Sorted List ADT.

Here is function definition that is given to me:
SplitLists(SortedType list, ItemType item, SortedType& list1, SortedType& list2)

Function: Divides the list into two lists according to the key of terms

Pre: list has been initialized and is not empty

Post: list1 contains all the items of the list whos keys are less than or equal to items key:

list2 contains all the items of list whose keys are greater than item's key

Explanation / Answer

Below is the member function named SplitLists. O(N^2) is the running time using Big-O.

void SplitLists(const SortedType& list, ItemType item,SortedType& list1, SortedType& list2)
{
ItemType listItem;

list1.MakeEmpty();
list2.MakeEmpty();
list.ResetList();

while (!list.IsLastItem()) {
   list.GetNextItem(listItem);
   if(listItem > item)
list2.InsertItem(listItem);
else
list1.InsertItem(listItem);
}
}

Good Luck !!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote