Question
C++ UNSORTED LIST This a C++ program related to Unsorted list as a linked structure (even though I called it sorted list). I get 5
C++ UNSORTED LIST
This a C++ program related to Unsorted list as a linked structure (even though I called it sorted list). I get 5 errors in my code (I think all of them from "GetItem" function) and don't know how to fix it.
//HEADER
#include
#include
using namespace std;
// classs sortedype
struct NodeType;
class SortedType {
public:
//constructor
SortedType();
void MakeEmpty();
bool IsFull () const;
int GetLength() const;
int GetItem(int item, bool& found);
void PutItem(int item);
//void DeleteItem(int item);
void ResetList();
int GetNextItem();
~SortedType();
private:
NodeType* listData;
int length;
NodeType* currentPos;
};
///////////////////////////////////////////////////////////////////////
#include
#include "SortedList.h"
using namespace std;
struct NodeType
{
int info;
NodeType* next;
};
SortedType::SortedType() //length starts at = 0
{
length = 0;
listData = NULL;
} //complete
bool SortedType::IsFull() const {
NodeType* location;
try
{
location = new NodeType;
delete location;
return false;
}
catch (bad_alloc exception)
{
return true;
} //cpmplete
}
int SortedType::GetLength() const { //return length
return length;
} //complete
void SortedType::MakeEmpty()
{
NodeType* tempPtr;
while (listData != NULL)
{
tempPtr = listData;
listData = listData -> next;
delete tempPtr;
}
length = 0;
} //complete
/*int SortedType::getListElement(int i) //return list
{
return list[i];
}*/
void SortedType::PutItem(int item) //
{
NodeType* location; //declare pointer to node
location = new NodeType;
location->info = item;
location->next = listData;
listData = location;
length++;
} //complete
int SortedType::GetItem(int item, bool& found)
{
bool moreToSearch;
NodeType* location;
location = listData;
found = false;
moreToSearch = (location != NULL);
while (moreToSearch && !found)
{
switch (item.ComparedTo(info[location]))
{
case 10:
case 20: location = location->next;
moreToSearch = (location != NULL);
break;
case 15: found = true;
item = location->info;
break;
}
}
return item;
} //complete
SortedType::~SortedType()
{
NodeType* tempPtr;
while (listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
}
void SortedType::ResetList()
{
currentPos = NULL;
} //complete
int SortedType::GetNextItem()
{
if (currentPos == NULL)
currentPos = listData;
else
currentPos = currentPos->next;
return currentPos->info;
}
ERRORS:
error C2228: left of '.ComparedTo' must have class/struct/union _sortedlists\sortedlist.cpp(99): note: type is 'int' _sortedlists\sortedlist.cpp(99): error C2065: 'info': undeclared identifier _sortedlists\sortedlist.cpp(99): fatal error C1903: unable to recover from previous error(s)
Step 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