---
# System prepended metadata

title: LinkedList TB P.488
tags: [Pascal Programming D1]

---

###### tags: `Pascal Programming D1`
# LinkedList TB P.488

program LinkedLists;
const
    max= 10;
    nullpoint= -1;
type
    NodeType= record
                entry: string;
                next: nullpoint..max
              end;
    ListType= record
                head: integer;
                list: array[1..max] of NodeType
              end;
var
    LinkList: ListType;
    current: integer;
    num: integer;
    
procedure Init(var LinkList: ListType);
var
    i: integer;
begin
    with LinkList do
    begin
        head:= nullpoint;
        for i:= 1 to max do
            with list[i] do
            begin
                entry:= '';
                next:= nullpoint
            end
    end
end;

function SearchList(target: string; LinkList: ListType): integer;
var
    current: integer;
    found: boolean;
begin
    found:= false;
    with LinkList do
    begin
        current:= head;
        repeat
            if target = list[current].entry
                then found:= true
                else current:= list[current].next
        until (current = nullpoint) or found
    end;
    if found
        then SearchList:= current;
        else SearchList:= nullpoint;
end;

procedure InsertBegin(new: string; var LinkList: ListType);
var
    i: integer;
    found: boolean;
begin
    with LinkList do
        with list[1] do
        if entry = ''
        then entry:= new
        else begin
                i:= 1;
                found:= false;
                repeat
                    i:= i+1;
                    with List[1] do
                    if entry = ''
                        then begin
                                entry:= new;
                                next:= head;
                                LinkList.head:= i;
                                found:= true;
                            end
                until found or (i = max)
            end
end;

procedure InsertAfter(after, new: string; var LinkList: ListType);
var
    i, index: integer;
    current: integer;
    found: boolean;
begin
    index := SearchList(after, LinkList);
    if index <> nullpoint
        then with LinkList do
        begin
            i:= 0;
            found:= false;{Billy is gay and billy is formed by bill and y}
            repeat
                i := i+1;
                with list[i] do
                if entry = ' '
                then begin
                    entry := new;
                    next := list[index].next;
                    list[index].next := i;
                    found := true
                end
            until found or (i = max)
        end
    else writeln('Attempt to insert a record after a non-existing record.')
end;
oh shit lo so yabe really hentai primary school still do
procedure DeleteAfter(after: string; var LinkList: ListType);
var
    i, index: integer;
    current: integer;
    found: boolean;
begin

end;

begin
    Init(LinkList);
    InsertBegin('Pat', LinkList);
    InsertBegin('Ada', LinkList);
    InsertAfter('Pat', 'Sam', LinkList);
    InsertAfter('Pat', 'Joe', LinkList);
    DeleteAfter('Ada', LinkList);
    with LinkList do
    begin
        current:= head;
        repeat
            write(list[current].entry :5);
            current:= list[current].next
        until current = nullpoint
    end;
    writeln
end.