Author Message

[ Pascal.PAS 1K ]

{ Here's an example of a linked list.
I have 2 questions.

1.) Where and how do you add Dispose() when finishing the program?

2.) Is it possible to implement a way to do a (fast) access to
say, record 23411 ?
or do I have to start with number 1 and step one by one until I
reach number 23411 ?

-------------------------------------------------------------------}

USES Crt, Dos;

TYPE
Postpointer = ^Post;

Post = Record
X    : Word;
Y    : word;
Next : Postpointer;
End;

VAR
First, This, Last, Newrec : Postpointer;
a,b : word;
i:LongInt;

{+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +}
PROCEDURE Input_value;
begin
clrscr;
A:=I;
B:=A;
end;

{+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +}
PROCEDURE Input2List;
Begin
{- - - - - - - - - - - - -  }
New(Newrec);

{- - - - - - - - - - - - -  }
Newrec^.X := a;
Newrec^.Y :=  b;
Newrec^.Next := Nil;

{- - - - - - - - - - - - -  }
If First = Nil then Begin
First := Newrec;
Last  := Newrec;
End else Begin
Last^.Next := Newrec;
Last  := Newrec;
End;
Newrec := Nil;
End;

{+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + }
PROCEDURE Printout;
Begin
This := First;
While not (This^.Next = Nil) do Begin
Write(This^.X,' ',This^.Y);
Write(' ');
This := This^.Next;
end;
Write(This^.X,' ',This^.Y);
end;

{////////////////////////////////////////////////////////////////////////}
BEGIN
First := Nil;
This  := Nil;
Last  := Nil;
Newrec    := Nil;

For i := 1 to 4000 do begin
Input_value;
Input2List;
end;
Printout;
END.

Sun, 27 Feb 2000 03:00:00 GMT

Quote:

>{ Here's an example of a linked list.
>  I have 2 questions.

[snip]

...red

--
Support the anti-Spam amendment
Join at http://www.cauce.org/

Mon, 28 Feb 2000 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages