From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d4c0eb138f4953e2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-01 16:52:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!falcon.america.net!eagle.america.net.POSTED!not-for-mail Message-ID: <3C32594E.303334A6@otelco.net> From: Larry Hazel X-Mailer: Mozilla 4.78 [en] (Win98; U) X-Accept-Language: en,x-ns11F8K63r3NhQ,x-ns2r2e09OnmPe2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Non destructive summation of nodes (Linked List/FIFO Queue) References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 01 Jan 2002 18:50:22 -0600 NNTP-Posting-Host: 66.0.32.230 X-Trace: eagle.america.net 1009932724 66.0.32.230 (Tue, 01 Jan 2002 19:52:04 EST) NNTP-Posting-Date: Tue, 01 Jan 2002 19:52:04 EST Organization: 24hoursupport.com Xref: archiver1.google.com comp.lang.ada:18426 Date: 2002-01-01T18:50:22-06:00 List-Id: Liddle Feesh wrote: > > 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 > Your package doesn't have a non-destructive get function or a way to iterate over the queue getting each element Looks like you need these. Modify the queue package to add them. Larry