comp.lang.ada
 help / color / mirror / Atom feed
From: "bklungle" <bklungle@ix.netcom.com>
Subject: Re: Code Confusion.
Date: 1997/11/02
Date: 1997-11-02T14:39:32-08:00	[thread overview]
Message-ID: <63ivf4$m5@sjx-ixn5.ix.netcom.com> (raw)
In-Reply-To: 345CD154.1249E04E@eng.ua.edu


At a quick glance, it looks like your code is generating a single node loop
on itself (among other things.)
Using your constructs, one possible sequence for building a push-down stack
linked list of nodes could be as follows:
..
..
begin  --lab10A
  -- assuming a use clause was given for text_io (or equivalent)
  put("Please enter the number of nodes desired ");
  -- assuming a new and use clause was given for integer_io (or equivalent)
  get(NUM_NODES);  -- get integer number of nodes
  skip_line;                   -- make sure no garbage at end of line
  if NUM_NODES /= 0 then
    HEAD := new LIST_NODE;
    put("Please enter integer node value for node 1: ");
    get(HEAD.NUM);    -- get nodes integer value
    skip_line;                 -- make sure no garbage at end of line
    for i in 2 .. NUM_NODES loop
      P := new LIST_NODE;  -- get another dynamic node
      P.NEXT := HEAD;           -- link current head behind this one
      HEAD    := P;                   -- this is now the current head
      put("Please enter integer node value for node " & integer'image(i) & "
");
      get(P.Num);
      skip_line;              -- make sure no garbage at end of line
    end loop;
    .
    .
  end if;

  -- Note: This is not the best, or only way to do this, only one quick way.

Cheers...bob

Supreme wrote in message <345CD154.1249E04E@eng.ua.edu>...
>In the following program I am trying to display the values of linked
>list instead my output is
>80 80 80 80 80 80
>instead of 40 50 60 70 80.
>here it is.
>procedure problem is
>    type LIST_NODE;
>    type NODE_PTR is access LIST_NODE;
>    type LIST_NODE is record
>                NUM : INTEGER;
>                NEXT : NODE_PTR;
>     end record;
>
>HEAD,P  : NODE_PTR;
>N, NUM_NODES : INTEGER;
>begin -- lab10A
>    Put("Please enter the the values of the nodes");
>Get( Num_Nodes);
>Head := new NODE;
>New_Line;
>P := Head;
>    for K in 2..NUN_NODES loop
>Head.Next := P;
>P.ALL.NUM := N;
>P := P.Next;
>end loop;
>    Will this allow teh user to assing 20 30 40 50 etc to the linked
>list?
>in other words
>Head.Next := P Should point the Head.next to the Pointer P and
>then P.ALL.NUM :=N should be set to the value of N  ( entered by the
>user)
>then P := P.Next should allow N to be assigned to the next pointer.
>is this right??
>Peace.
>






  reply	other threads:[~1997-11-02  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-02  0:00 Code Confusion Supreme
1997-11-02  0:00 ` bklungle [this message]
1997-11-04  0:00 ` Bill
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox