UnsortedList::UnsortedList()
{
length = 0;
}
UnsortedList::~UnsortedList() {}
void UnsortedList::insertItem(int id)
{
idNumbers[length] = id;
length++;
}
void UnsortedList::deleteItem(int id)
{
int location = 0;
while (id != idNumbers[location] && location < length)
location++;
// if (location < length)
// {
// idNumbers[location] = idNumbers[length - 1];
// length--;
// }
if (idNumbers[length] == id) // both work
{
idNumbers[location] = idNumbers[length-1];
length--;
}
if (location == length)
{
cout << "The item is not in the list." << endl;
}
}
bool UnsortedList::isFull() const
{
return (length == SIZE);
}
bool UnsortedList::isEmpty() const
{
return (length == 0);
}
void UnsortedList::displayList() const
{
int location = 0;
while (location < length)
{
cout << idNumbers[location] << endl;
location++;
}
if (location > length)
{
cout << "The list is empty." << endl;
}
}