Original Post
Here's my Linked list classes:
And there's two thing's I wonder about it.
1. How I may improve it to be faster (or easier to understand without speed change).
2. I'd like to use different data-types in the list. So the list can (almost) deal with whatever data-type it's given. I've tried to inherit the LL_Data (in the same way as the Node class is in my code) in my other classes but without success.
This gives me the error message: cannot convert from 'class LL_Data *' to 'class LL_Data2 *' (as expected)
Help would be greatly appreciated.
[edited by - dta1 on August 5, 2002 7:41:40 PM]
class LL_Data
{
public:
LL_Data() {}
LL_Data(int val):myValue(val) {}
int myValue;
};
class Node
{
public:
Node() {}
virtual ~Node() {}
virtual LL_Data *GetData(USHORT num) = NULL;
};
class TailNode : public Node
{
public:
TailNode() {}
~TailNode() {}
virtual LL_Data *GetData(USHORT num); // Returns error, could not find a node with that number.
};
class BodyNode : public Node
{
public:
BodyNode(LL_Data *theData, Node *nextNode, USHORT num): myData(theData), myNext(nextNode), myNum(num) {}
~BodyNode() { delete myData; delete myNext; }
virtual LL_Data *GetData(USHORT num);
private:
USHORT myNum;
LL_Data *myData;
Node *myNext;
};
class LinkedList
{
public:
LinkedList():numNodes(0) { myHead = new TailNode; };
~LinkedList() { delete myHead; };
void InsertData(LL_Data *theData);
LL_Data *GetData (USHORT num);
const USHORT GetListSize() { return numNodes; }
private:
Node *myHead;
USHORT numNodes;
};
class LL_Data2 : public LL_Data
{
public:
LL_Data2(int val):myOtherValue(val*10) {}
int myOtherValue;
};