Sample code for a linked list implementation - Delphi pointer free :-)
Feel free to improve!
program linkedlist;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var storage : Array[1 .. 20] of string;
var pointer : Array[1 .. 20] of integer;
var freelist: Array[1..20] of integer;
var liststart : integer;
var freestart : integer;
procedure additem(itemstring:string);
var lastitem : boolean;
item : integer;
begin
lastitem := false;
item := liststart;
// search through the list for the end
while not lastitem do
begin
write('.');
if pointer[item] = 0 then
begin
writeln;
//writeln('found end of list at position ', item);
lastitem := true;
end else begin
item := pointer[item];
end;
// item should now point at the end of the list
end;
// now put the item at freestart
storage[freestart] := itemstring;
// set the pointer at the old list end to the new item
pointer[item] := freestart;
// mark this new position as the end of the list
pointer[freestart] := 0;
// and update freestart to the next item on the list
freestart := freelist[freestart];
end;
procedure displayitems;
var i : integer;
begin
for i := 1 to 20 do
begin
writeln(i,':',freelist[i],'->',storage[i],'<-',pointer[i]);
end;
writeln('First free item is position ',freestart);
readln;
end;
procedure deleteitem(itemno: integer);
var foundit : boolean;
item : integer;
begin
foundit := false;
item := 1;
// search through the list for the item
// we need to find what record comes before it
// so that we can adjust the pointer
while not foundit do
begin
if pointer[item] = itemno then
begin
foundit := true;
end else begin
item := pointer[item];
end;
end;
// got it. Now copy the pointer of the deleted item
// to the previous item
pointer[item] := pointer[itemno];
// remove the item text
storage[itemno] := '';
// and adjust the freelist to start in the vacant slot
// first make sure that the list item points to the old first item
freelist[itemno] := freestart;
// then make the start position this new 'hole'
freestart := itemno;
end;
procedure setup;
var i : integer;
begin
liststart := 1;
freestart := 1;
for i := 1 to 19 do
begin
pointer[i] := 0;
freelist[i] := i+1 ;
end;
freelist[20] := 0;
end;
begin
setup;
additem('Tinker');
additem('Tailor');
additem('Soldier');
additem('Spy');
deleteitem(2);
additem('Candlestickmaker');
displayitems;
readln;
end.