My assignment requires the creation of a package that creates a heterogeneous (using inheritance) doubly linked list. Inserting nodes into the list is simple enough, but my issue comes in when I have to locate a node containing certain information.
PACKAGE AbstList IS
TYPE AbstractList IS LIMITED PRIVATE;
TYPE Node IS TAGGED PRIVATE;
TYPE NodePtr IS ACCESS ALL Node'Class;
PROCEDURE Init_Head(List: ACCESS AbstractList);
PROCEDURE InsertFront(List: ACCESS AbstractList; Item: IN NodePtr; Success: OUT Boolean);
PROCEDURE InsertRear(List: ACCESS AbstractList; Item: IN NodePtr; Success: OUT Boolean);
FUNCTION ListSize(List: ACCESS AbstractList) RETURN Integer;
-- The following are commented out as they are not complete in the package body
--FUNCTION FindItem(List: ACCESS AbstractList; Value: NodePtr) RETURN NodePtr;
--PROCEDURE Delete(List: ACCESS AbstractList; Item: NodePtr);
--PROCEDURE Print(List: ACCESS AbstractList);
PRIVATE
TYPE Node IS TAGGED RECORD
Rlink, Llink: NodePtr;
END RECORD;
TYPE AbstractList IS LIMITED RECORD
Count: Integer := 0;
Head: NodePtr := NEW Node;
END RECORD;
END AbstList;
One such record that I am using to insert into the list is the following:
TYPE CarName IS (GMC, Chevy, Ford, RAM);
TYPE Car IS NEW AbstList.Node WITH RECORD
NumDoors: Integer;
Manufacturer: CarName := GMC; -- Default manu.
END RECORD;
So for example, how could I find a node in the list that contains a specified "Manufacturer"? It was suggested to me that I overload the "=" operator, though I am not sure how this would work given what I have. Any suggestions would be appreciated.