comp.lang.ada
 help / color / mirror / Atom feed
From: "Liddle Feesh" <no_see_reply_address@spam.com>
Subject: Non destructive summation of nodes (Linked List/FIFO Queue)
Date: Tue, 1 Jan 2002 23:02:59 -0000
Date: 2002-01-01T23:02:59+00:00	[thread overview]
Message-ID: <MerY7.24617$Zg2.2575659@news11-gui.server.ntli.net> (raw)

Hi,

Firstly - thankyou to everyone (Larry Hazel, Gautier, Ed Falis, Michal
Nowak, Machael Bode & others) for your kinds assitance in helping me take my
first steps in the great language of Ada95.

I am a little confused, however - at how to count the number of items in a
linked list, without destroying the items in the process.

Basically, I want to do this:

If queue is empty
        display warning message
Else
        loop while next pointer on node is not null
                    print node's value
        end loop
        print last node's value
end if

*So that I can loop through all the nodes. If this isn't possible, then
another solution could be:*

Declare Count_Of_Elements as Integer
Set Count_Of_Elements = 0
While Not Queue.Head = null
          Increment Count_Of_Elements = Count of Elements + 1 -- (Increment
Count)
End Loop
Print Count_Of_Elements


----
However, writing the above in Ada without destroying the queue is tricky.
Michal suggested:

while not (Queue.Is_Empty_Queue(Queue) ) loop
        Queues.Remove (Element, Queue);
        Put(Element);
        New_Line;
end loop;

------

However, the above basically removes each node whilst 'counting' back the
values stored in each.

And for those that have just joined this conversation, I am trying to create
a display function/procedure that gives me a count of the elements in the
queue.

TIA!

Mike

--
Liddle Feesh
 '  O 0 o <"//><  ' o'^
(Remove UNDERPANTS to reply)







             reply	other threads:[~2002-01-01 23:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-01 23:02 Liddle Feesh [this message]
2002-01-02  0:50 ` Non destructive summation of nodes (Linked List/FIFO Queue) Larry Hazel
2002-01-02  2:06 ` Larry Hazel
2002-01-02  2:41   ` James Rogers
2002-01-02 11:17 ` Michal Nowak
replies disabled

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