Question
In todays lab we will design and implement the List ADT where the items in the list are sorted. c++ language sortedtype.h #ifndef SORTEDTYPE_H_INCLUDED #define
In todays lab we will design and implement the List ADT where the items in the list are sorted. c++ language
sortedtype.h #ifndef SORTEDTYPE_H_INCLUDED #define SORTEDTYPE_H_INCLUDED template class SortedType { struct NodeType { ItemType info; NodeType* next; }; public: SortedType(); ~SortedType(); bool IsFull(); int LengthIs(); void MakeEmpty(); void RetrieveItem(ItemType&, bool&); void InsertItem(ItemType); void DeleteItem(ItemType); void ResetList(); void GetNextItem(ItemType&); private: NodeType* listData; int length; NodeType* currentPos; }; #endif // SORTEDTYPE_H_INCLUDED sortedtype.cpp #include "sortedtype.h" #include using namespace std; template SortedType length = 0; listData = NULL; currentPos = NULL; } template int SortedType return length; } template bool SortedType NodeType* location; try { location = new NodeType; delete location; return false; } catch(bad_alloc& exception) { return true; } } | template void SortedType NodeType* newNode; NodeType* predLoc; NodeType* location; bool moreToSearch; location = listData; predLoc = NULL; moreToSearch = (location != NULL); while (moreToSearch) { if (location->info < item) { predLoc = location; location = location->next; moreToSearch = (location != NULL); } else moreToSearch = false; } newNode = new NodeType; newNode->info = item; if (predLoc == NULL) { newNode->next = listData; listData = newNode; } else { newNode->next = location; predLoc->next = newNode; } length++; } template void SortedType NodeType* location = listData; NodeType* 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--; }
Generate the driver file (main.cpp) where you perform the following tasks. Note that you cannot make any change to the header file or the source file.
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started