C++ Splitlists( listType& list1, listType& list2,ItemType item) Function: Divides list into two lists according to the key of item. Precondition: 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 key. List2 contains all the items of list whose keys are greater than items key. driver (.cpp) file in which you declare two objects of class Unsorted List one of which contains integers into info part and the other one contains characters into info part. Both objects should not have less than 20 nodes. a. Implement splitLists as a member function of the Unsorted List ADT. #include #ifndef UNSORT_H #define UNSORT_H template

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++

Splitlists( listType& list1, listType& list2,ItemType item) Function: Divides list into two lists according to the key of item. Precondition: 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 key. List2 contains all the items of list whose keys are greater than items key.

driver (.cpp) file in which you declare two objects of class Unsorted List one of which contains
integers into info part and the other one contains characters into info part. Both objects should not have
less than 20 nodes.

a. Implement splitLists as a member function of the Unsorted List ADT.

#include<iostream>
#ifndef UNSORT_H
#define UNSORT_H
template <class ItemType>
struct NodeType
{
   ItemType info;
   NodeType* next;
};
template <class ItemType>
class UnsortedType
{
public:
   UnsortedType();
   ~UnsortedType();
   bool full() const;
   int lengthIs() const;
   void makeEmpty();
   void retrieveItem(ItemType& item, bool& found);
   void insertItem(const ItemType& item);
   void deleteItem(const ItemType& item);
   void resetList();
   void getNextItem(ItemType& item);
   bool atEnd();
private:
   NodeType<ItemType>* listData;
   int length;
   NodeType<ItemType>* currentPos;
};

template <class ItemType>
UnsortedType<ItemType>::UnsortedType()
{
   length = 0;
   listData = NULL;
}
template <class ItemType>
UnsortedType<ItemType>:: ~UnsortedType()
{
   NodeType<ItemType>* location;

   while (listData != NULL)
   {
       location = listData;
       listData = listData->next;
       delete location;
   }
   length = 0;
}
template <class ItemType>
bool UnsortedType<ItemType>::full() const
{
   NodeType<ItemType>* ptr;
   ptr = new NodeType<ItemType>;
   if (ptr == NULL)
       return true;
   else
   {
       delete ptr;
       return false;
   }
}
template <class ItemType>
int UnsortedType<ItemType>::lengthIs() const
{
   return length;
}
template <class ItemType>
void UnsortedType<ItemType>::makeEmpty()
{
   NodeType<ItemType>* location;

   while (listData != NULL)
   {
       location = listData;
       listData = listData->next;
       delete location;
   }
   length = 0;
}
template <class ItemType>
void UnsortedType<ItemType>::retrieveItem(ItemType& item,
   bool& found)
{
   bool moreToSearch;
   NodeType<ItemType>* location;

   location = listData;
   found = false;
   moreToSearch = (location != NULL);

   while (moreToSearch && !found)
   {
       if (item == location->info)
       {
           found = true;
           item = location->info;
       }
       else
       {
           location = location->next;
           moreToSearch = (location != NULL);
       }
   }
}
template <class ItemType>
void UnsortedType<ItemType>::insertItem(const ItemType & item)
{
   NodeType<ItemType>* location;
   location = new NodeType<ItemType>;
   location->info = item;
   location->next = listData;
   listData = location;
   length++;
}
template <class ItemType>
void UnsortedType<ItemType>::deleteItem(const ItemType& item)
{
   NodeType<ItemType>* location = listData;
   NodeType<ItemType>* tempLocation;
   if (item == listData->info)
   {
       tempLocation = location;
       listData = listData->next;
   }
   else
   {
       while (!(item == (location->next)->info))
           location = location->next;
       tempLocation = location->next;
       location->next = (location->next)->next;
   }
   delete tempLocation;
   length--;
}
template <class ItemType>
void UnsortedType<ItemType>::resetList()
{
   currentPos = NULL;
}
template <class ItemType>
void UnsortedType<ItemType>::getNextItem(ItemType& item)
{
   if (currentPos == NULL)
       currentPos = listData;
   else
       item = currentPos->info;
   currentPos = currentPos->next;
}
template <class ItemType>
bool UnsortedType<ItemType>::atEnd()

{
   return currentPos == NULL;
}
#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY