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

PLEASE DO THIS PROGRAM DO NOT GIVE ME A SAMPLE!! PLEASSSSEEE! Implement an Unsor

ID: 3747727 • Letter: P

Question

PLEASE DO THIS PROGRAM DO NOT GIVE ME A SAMPLE!! PLEASSSSEEE!

Implement an Unsorted List ADT using a linked list implementation with an extension of ADT with function SplitLists (Exercise 3 from Chapter 3, p. 185). Keep the function names the same as in Unsorted List ADT in Chapter 3.

SplitLists function requirements:

SplitLists(UnsortedType list, ItemType item, UnsortedType& list1, UnsortedType& list2)

Function: divides list into two lists according to the key of item

Preconditions: list has been initialized and is not empty

Postconditions: list1 contains all the items of list whose keys are less than or equal to item’s key; list2 contains all the items of list whose keys are greater than item’s key

a. Implement SplitLists as an array-based member function of the Unsorted List ADT.

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

Explanation / Answer


void UnsortedType::SplitLists(UnsortedType& list, ItemType item, UnsortedType& list1, UnsortedType& list2)
// Pre: list has been initialised and is not empty
// Post: list1 contains all the items of list whose keys are less
//       than os equal to item's key;
//       list2 contains all the items of list whose keys are greater
//       than item'; key.
{

// Some variables
ItemType currentItem;
int length = list.GetLength();

// First, start at the beginning of list
list.ResetList();
// And make sure the two other lists are empty
list1.MakeEmpty();
list2.MakeEmpty();
for(int counter = 0; counter < length; counter++)
    {
      currentItem = list.GetNextItem();
    
      if(GREATER == currentItem.ComparedTo(item))
   list2.PutItem(currentItem);
      else
   list1.PutItem(currentItem);
}

}

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