(*====================================================================*) (* Peter M. Perchansky *) (* 412-1 Springside, Drive East *) (* Shillington, PA 19607 *) (* *) (* CompuServe 71301,344 *) (* FidoNet 1:273/101 *) (* Interlink *) (*====================================================================*) Generic Deque Notes: Don't let the ARRAY OF BYTE, ADDRESS, or ARRAY OF WORD scare you when you look at generic procedures or modules. Calling a generic procedure can be very simple. Here's an example: ---- MODULE Person; FROM PMPDeque IMPORT Deques (* type *), Enqueue, Dequeue, InQueue; FROM PMPDeque IMPORT CreateDeque, DestroyDeque; TYPE PersonRec = RECORD lastName : ARRAY [0..24] OF CHAR; firstName : ARRAY [0..14] OF CHAR; middleInitial : CHAR; age : CARDINAL; END; VAR person : PersonRec; queue : Deques; ok : BOOLEAN; (* used to check for queue errors *) BEGIN CreateDeque (queue); (* make queue NIL *) WITH person DO lastName := "Fieldings"; firstName := "Robert; middleInitial := "M"; age := 26; END; Enqueue (person, queue, ok); (* place Robert in queue *) IF NOT ok THEN (* handle queue overflow --- not enough memory --- error *) END; WITH person DO lastName := "Yoritomo"; firstName := "Shakari; middleInitial := " "; age := 37; END; Enqueue (person, queue, ok); (* place Shakari in queue *) IF NOT ok THEN (* handle queue overflow --- not enough memory --- error *) END; WITH person DO lastName := "Fieldings"; firstName := "Robert; middleInitial := "M"; age := 26; END; IF InQueue (person, queue) THEN (* Robert is in queue *) ELSE (* Robert is not in queue *) END; Dequeue (person, queue, ok); (* serve person in front of queue *) (* Robert in this case *) IF NOT ok THEN (* handle queue underflow --- queue is empty --- *) (* possibility also exists that the type being *) (* retrieved is not the same type that was stored *) END; .... (* and so on *) ... DestroyDeque (queue); (* remove queue from memory *) END Person; The same module, or another, could have created a variable called stack of type Deques and used stack operations (push, pop, top, etc.). As you can tell, you don't have to worry about ARRAYs OF BYTE, or ADDRESSes, or ARRAYs OF WORDs. That's why using and writing generic procedures can be very helpful. The main area to be careful when writing or using generic procedures or modules is you, the programmer, are responsible for keeping track of types you are storing or manipulating. For instance, you can have used Enqueue (or Push) to place variables of type INTEGER (or whatever) in the same queue you placed variables of type PersonRec. That's where the danger lies --- keeping careful track of what types you store. Although you can mix types in a generic dequeue, it's highly advisable you set up a separate stack, queue, deque, etc. for each data type you plan on manipulating or storing. Please feel free to contact me via postal mail, CompuServe, FidoNet, or Interlink (language or Pascal Conference ) if you have any questions or comments.