home *** CD-ROM | disk | FTP | other *** search
- {
-
- flex.pas // FlexList
- 4-23-90
- Generic hybrid stack-queue-list-array object.
-
- Copyright 1990
- John W. Small
- All rights reserved
-
- PSW / Power SoftWare
- P.O. Box 10072
- McLean, Virginia 22102 8072
-
-
- Anytime your Turbo Pascal application requires a stack,
- queue, or linked list, simply include "flex" in its
- "uses" clause. Next declare your stack, queue, or list
- as a variable of type "FlexList". FlexList is a hybrid
- stack-queue-list-array generic data structure. Your
- FlexList variable can be initialized to store any type
- of data. The FlexList object has over 30 methods for
- accessing your "list" as a stack, queue, list, or array
- interchangeably! You can push, pop, ins, del, sort,
- store, recall, or find to name but just a few operations.
- FlexList methods allows you to access your list's data
- by value (copy) or by reference (pointer) as well as to
- move nodes directly between lists. And your
- application's code size won't continue to grow when you
- add new types of lists either, since the FlexList object
- is generic, able to hold any type of data, record or
- object. Since FlexLists are initialized at run time,
- the data they hold or even their creation can be
- specified at run time thus allowing your application new
- dimensions of adaptibility to user inputs. And with
- FlexList you can quickly construct lists of lists or
- other composite structures. FlexList will save you
- time, money, code space and headaches!
-
-
- For example:
-
- var intStack : FlexList;
-
- begin
- writeln('Count backwards from ten.');
- intStack.init(sizeof(integer));
- for i := 1 to 10 do
- intStack.push(i);
- intStack.pop(i);
- while intStack.ok do begin
- writeln(i);
- intStack.pop(i)
- end
- write('Press ''Enter'' to quit.');
- readln
- end.
-
-
- }
-
- unit flex;
-
- interface
-
- type
-
- FlexData = word;
-
- FlexN = ^FlexNode;
- FlexNode = record
- { private: }
- next, prev : FlexN;
- { public: }
- data : FlexData
- end;
-
- FlexCompare = function (var data1, data2) : integer;
-
- FlexL = ^FlexList;
- FlexList = object
- { private: }
- front, current, rear : FlexN;
- { public, read only: }
- curNum, nodes, sizeofData, sizeofNode,
- { public: }
- sizeofLastPack, sizeofLastPackPtrs : word;
- ok : boolean;
- constructor init(dataSize : word);
- constructor unpack(cellSize, cells : word;
- var arrayBuf);
- procedure clear;
- procedure push(var data);
- procedure pushN(n : FlexN);
- procedure pop(var data);
- function popN : FlexN;
- procedure top(var data);
- function frontD : pointer;
- procedure insQ(var data);
- procedure insQN(n : FlexN);
- function rearD : pointer;
- procedure mkcur(loc : word);
- function currentD : pointer;
- procedure ins(var data);
- procedure insN(n : FlexN);
- procedure insSort(var data;
- compare : FlexCompare);
- procedure insSortN(n : FlexN;
- compare : FlexCompare);
- procedure del(var data);
- function delN : FlexN;
- function next(var data) : boolean;
- function nextD(var d : pointer) : boolean;
- function prev(var data) : boolean;
- function prevD(var d : pointer) : boolean;
- procedure get(var data);
- procedure put(var data);
- procedure store(var data; location : word);
- procedure recall(var data; location : word);
- function find(var data; compare : FlexCompare)
- : boolean;
- procedure sort(compare : FlexCompare);
- function pack : pointer;
- function packPtrs : pointer;
- destructor done;
- end;