my problem is that when I try and run it it says 'SortedList' : cannot instantiate abstract class due to following members: 'bool BasicADT::isEmpty(void) const' : is abstract ...and... 'int BasicADT::getLength(void) const' : is abstract
can someone please tell me what I am doing wrong with my getLength and isEmpty.
BasicADT...
class BasicADT // abstract base class
{
public:
virtual bool isEmpty() const = 0;
virtual int getLength() const = 0;
}; // end BasicADT
SortedList.h...
#include "BasicADT.h"
typedef int ListItemType; // This is not a template class!
class SortedList : public BasicADT
{
public:
// constructor:
SortedList();
// SortedList operations:
bool IsEmpty() const
{ return Head == 0;}
int GetLength() const
{ return size;}
void sortedInsert(const ListItemType& newItem);
void sortedRemove(const ListItemType& anItem);
void sortedRetrieve(int index, ListItemType& anItem) const;
private:
int size;
class Node{
public:
ListItemType info;
Node* next;
};
typedef Node* nodePtr;
nodePtr Head;
}; // end SortedList
SortedList.cpp...
#include "SortedList.h"
#include <iostream>
SortedList::SortedList()
{
Head = NULL;
size = 0;
}
void SortedList::sortedInsert(const ListItemType& newItem)
{
nodePtr newNode = new Node, it = Head;
newNode->info = newItem;
newNode->next = NULL;
if(IsEmpty())
{
size ++;
Head = newNode;
}
else
{
while(it->next && it->next->info < newItem)//traverse to last node
it = it->next;
newNode->next = it->next;
it->next = newNode;
size++;
}
}
void SortedList::sortedRemove(const ListItemType& anItem)
{
nodePtr it, prev;
if(IsEmpty())
return;
else if(Head->info == anItem)//if first element
{
size --;
it = Head->next;
delete Head;
Head = it;
sortedRemove(anItem);//recall incase item appears multiple times at beginning
}
else
{
it = Head;
while(it->next)
{
if(it->info == anItem)
{
prev->next = it->next;
it = prev;
size --;
sortedRemove(anItem);//recall incase item reappears in a row
}
else
{
prev = it;
it = it->next;
}
}
}
}
void SortedList::sortedRetrieve(int index, ListItemType& anItem) const
{
int count = 1;
nodePtr it = Head;
if(index > size || isEmpty())//if index is greater than list size or list is empty
return;
else
{
while(it->next && count < index)
{
it= it->next;
count++;
}
anItem = it->info;
}
}
main...
#include "SortedList.h"
#include <iostream>
using namespace std;
int main()
{
SortedList myList;
return 0;
}