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

3. An Unsorted Type ADT is to be extended by the addition of function SplitLists

ID: 3591285 • Letter: 3

Question

3. An Unsorted Type ADT is to be extended by the addition of function SplitLists, which has the following specifications: SplitLists(UnsortedType list, ItemType item, UnsortedType&list1.; UnsortedType& list2) Function: Preconditions: Postconditions: Divides list into two lists according to the key of item. list has been initialized and is not empty. 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

Answer:

a)


void UnsortedType: :SplitLists(ItemType item, UnsortedType&
list1, unsortedtype& list2) function
//unsorted

{
int arr = 0;

//initialize variable

//call the method empty()

list1.MakeEmpty();
list2.MakeEmpty();

//arry based implementation
for (arr; arr < list1.GetLength(); arr++)
//get length of the list
if (info[arr].ComgaredTo(item) == GREAIER)
//if array is greater than to the item list 2 has inserted
list2.InsertItem(info[arr]);
//insert list2 item has inserted
else list1.InsertItem(info[arr]);

}


b)

void UnsortedType::SplitLists(ItemType item, UnsortedType&
list1, UnsortedType& list2)

{
NodeType* listP1 = listData;
//node type

while (listP1 != NULL)
//linked list pointer(listP1) is not equal to 0 till to work while
loop
{
if (listP1->info <= item)
//insert list 1

list1.InsertItemflistPl->info);

else
//insert list 2

list2.InsertItem(listPl->info);

listP1 = listPl->next;
}

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