
Originally Posted by
Wizzup?
You could set an initial array length of 1000. The array would be an array of some_record, and some_record would store a `value' and a `next' value. This next value would just be an Integer, the `next' index in the array. If you want a doubly linked list, also add a `previous' array index to the record.
Good idea, sigh now to create annoying procedures.
EDIT: I finished it, but I was wondering if anyone could see any obvious ways to optimize it since I'm gonna be using this quite a lot.
SCAR Code:
program New;
type path = record
node: TPointArray;
index: integer;
connection: array of integer;
end;
var paths:array of path;
curindex: integer;
function CreatePath(node:TPointArray):integer;
begin
SetArrayLength(paths, curindex+1);
paths[curindex].node := node;
paths[curindex].index := curindex;
result := curindex;
curindex := curindex + 1;
end;
procedure LinkPath(i,y:integer);
begin
SetArrayLength(paths[i].connection, GetArrayLength(paths[i].connection)+1);
paths[i].connection[High(paths[i].connection)] := paths[y].index;
end;
function blanktpa():TPointArray;
var empty:TPointArray;
begin
result := empty;
end;
var one,two,three:integer;
begin
one := CreatePath(blanktpa());
two := CreatePath(blanktpa());
three := CreatePath(blanktpa());
LinkPath(one,two);
LinkPath(two,three);
writeln(inttostr(paths[one].connection[0]));
writeln(inttostr(paths[two].connection[0]));
end.