Using the Sorted list created in deliverable 2, implement a linked stack data structure and store the elements of the so
Posted: Sun May 15, 2022 8:37 am
Using the Sorted list created in deliverable 2, implement a
linked stack data structure and store the
elements of the sorted list. Implement a recursive function
PrintRev(), that will print the content of the stack in reverse
order. This is my sorted list.
Sorted::Sorted()
{
length = 0;
}
bool Sorted::IsFull() const
{
return (length == MAX_ITEMS);
}
int Sorted::LengthIs() const
{
return length;
}
void Sorted::RetrieveItem(Malware& item, bool&
found)
{
int midPoint;
int first = 0;
int last = length - 1;
bool moreToSearch = first <= last;
found = false;
while (moreToSearch && !found)
{
midPoint = (first + last) / 2;
switch
(item.Compare(info[midPoint]))
{
case 1: last = midPoint - 1;
moreToSearch = first
<= last;
break;
case 2: first = midPoint + 1;
moreToSearch = first
<= last;
break;
case 0: found = true;
item =
info[midPoint];
break;
}
}
}
void Sorted::DeleteItem(Malware item)
{
int location = 0;
while (item.Compare(info[location]) != 0)
location++;
for (int index = location + 1; index < length;
index++)
info[index - 1] = info[index];
length--;
}
void Sorted::InsertItem(Malware item)
{
cout << "Insert Item called: \n";
bool moreToSearch;
int location = 0;
moreToSearch = (location < length);
while (moreToSearch)
{
switch
(item.Compare(info[location]))
{
case 1: moreToSearch = false;
break;
case 0:
moreToSearch =
false;
break;
case 2: location++;
location = (location <
length);
}
}
for (int index = length; index > location;
index--)
info[index] = info[index - 1];
info[location] = item;
length++;
}
void Sorted::ResetList()
// Post: currentPos has been initialized.
{
currentPos = -1;
}
void Sorted::GetNextItem(Malware& item)
// Post: item is current item.
// Current position has been updated.
{
currentPos++;
item = info[currentPos];
}
linked stack data structure and store the
elements of the sorted list. Implement a recursive function
PrintRev(), that will print the content of the stack in reverse
order. This is my sorted list.
Sorted::Sorted()
{
length = 0;
}
bool Sorted::IsFull() const
{
return (length == MAX_ITEMS);
}
int Sorted::LengthIs() const
{
return length;
}
void Sorted::RetrieveItem(Malware& item, bool&
found)
{
int midPoint;
int first = 0;
int last = length - 1;
bool moreToSearch = first <= last;
found = false;
while (moreToSearch && !found)
{
midPoint = (first + last) / 2;
switch
(item.Compare(info[midPoint]))
{
case 1: last = midPoint - 1;
moreToSearch = first
<= last;
break;
case 2: first = midPoint + 1;
moreToSearch = first
<= last;
break;
case 0: found = true;
item =
info[midPoint];
break;
}
}
}
void Sorted::DeleteItem(Malware item)
{
int location = 0;
while (item.Compare(info[location]) != 0)
location++;
for (int index = location + 1; index < length;
index++)
info[index - 1] = info[index];
length--;
}
void Sorted::InsertItem(Malware item)
{
cout << "Insert Item called: \n";
bool moreToSearch;
int location = 0;
moreToSearch = (location < length);
while (moreToSearch)
{
switch
(item.Compare(info[location]))
{
case 1: moreToSearch = false;
break;
case 0:
moreToSearch =
false;
break;
case 2: location++;
location = (location <
length);
}
}
for (int index = length; index > location;
index--)
info[index] = info[index - 1];
info[location] = item;
length++;
}
void Sorted::ResetList()
// Post: currentPos has been initialized.
{
currentPos = -1;
}
void Sorted::GetNextItem(Malware& item)
// Post: item is current item.
// Current position has been updated.
{
currentPos++;
item = info[currentPos];
}