Random access in linked lists??? 
Author Message
 Random access in linked lists???

[ 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  
 Random access in linked lists???

Quote:

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

[snip]

You got some good answers on your identical post to c.l.p.b

    ...red

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



Mon, 28 Feb 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Random access in a linked list

2. Taking list and outputing random list

3. Help Link List, Reverse Print List Node

4. Link List , use recursive routine to reverse print the node of the list

5. Doubly Linked List problem

6. Linked Lists

7. Sorting a linked list by multiple criteria

8. Linked Lists and Pointers

9. Linked List

10. Writting and Reading a linked list from/to a file

11. Record Link List Help please

12. Linked Lists Beyond the 640kb Limit

 

 
Powered by phpBB® Forum Software