}
// Returns NULL if no next Node
template
Node
{
return itsNext;
}
template
T * Node
{
if (itsObject)
return itsObject;
else
throw NullNode();
}
// **************** List ************
// Generic list template
// Works with any numbered object
// **********************************
template
class List
{
public:
List();
~List();
T* Find(int & position, int ObjectNumber) const;
T*GetFirst() const;
voidInsert(T *);
T*operator[](int) const;
intGetCount() const { return itsCount; }
private:
Node
int itsCount;
};
// Implementations for Lists...
template
List
pHead(0),
itsCount(0)
{}
template
List
{
delete pHead;
}
template
T*List
{
if (pHead)
return pHead->itsObject;
else
throw EmptyList();
}
template
T*List
{
Node
if (!pHead)
throw EmptyList();
if (offset > itsCount)
throw BoundsError();
pNode = pNode->itsNext; } // find a given object in list based on its unique number (id) template T*List { Node for (pNode = pHead, position = 0; pNode!=NULL; pNode = pNode->itsNext, position++) { if (pNode->itsObject->GetObjectNumber() == ObjectNumber) break; } if (pNode == NULL) return NULL; else return pNode->itsObject; } // insert if the number of the object is unique template void List { Node Node Node int Next = 0; itsCount++; { pHead = pNode; return; }
for (int i=0;i
return pNode->itsObject;
int New = pObject->GetObjectNumber();
if (!pHead)