Question
Solve the problem using C++. Make necessary changes in the following codes to complete the task. SortedList.h #ifndef SORTEDLIST_H #define SORTEDLIST_H template class SortedList{ struct
Solve the problem using C++. Make necessary changes in the following codes to complete the task.
SortedList.h
#ifndef SORTEDLIST_H #define SORTEDLIST_H
template
private: Node* listData; Node* currentPos; int length;
public: SortedList(); ~SortedList();
bool InsertItem(ItemType); bool DeleteItem(ItemType); void MakeEmpty();
bool RetrieveItem(ItemType&); bool GetNextItem(ItemType&); void ResetList(); int LengthIs();
bool IsFull(); bool IsEmpty();
};
#include "SortedList.tpp" #endif
SortedList.tpp
template
template
template
Node* predLoc = nullptr; Node* loc = listData;
while(loc != nullptr){ if(loc->info next; } else break; } if(predLoc == nullptr){ newNode->next = listData; listData = newNode; } else{ newNode->next = loc; predLoc->next = newNode; } length++; return true; }
template
if(IsEmpty()) return false;
if(listData->info == item) { Node *temp = listData; listData = listData->next; delete temp; } else{ Node* location = listData; while(item!=(location->next)->info){ location = location -> next; if(location->next == nullptr) return false; }
Node* temp = location->next; location->next = temp->next; delete temp; } length--; return true;
}
template
template
Node* location = listData; bool found = false;
while(location != nullptr){ if(location->info == item){ found = true; item = location->info; break; } else{ location = location->next; } } return found;
}
template
if(currentPos == nullptr) currentPos = listData; else if(currentPos->next == nullptr) return false; else currentPos = currentPos->next;
item = currentPos->info; return true;
}
template
template
template
template
main.cpp
#include
int main() { std::cout
1. Create a public function with function prototype "void Reverse();" in the Sorted List class. When called, this function should reverse the linked list. In the driver file (main.cpp): a. Create a float SortedList object. b. Insert a few items c. Call Reverse function. d. Print the listStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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