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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable 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-02 03:14:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: Michal Nowak Newsgroups: comp.lang.ada Subject: Re: Non destructive summation of nodes (Linked List/FIFO Queue) Date: Wed, 02 Jan 2002 12:17:45 +0100 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT X-Trace: avanie.enst.fr 1009970042 9919 137.194.161.2 (2 Jan 2002 11:14:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 2 Jan 2002 11:14:02 +0000 (UTC) To: "comp.lang.ada usegroup->mailing list gateway" Return-Path: In-reply-to: X-Mailer: Calypso Version 3.20.01.01 (3) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.6 Precedence: bulk X-Reply-To: vinnie@inetia.pl List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:18441 Date: 2002-01-02T12:17:45+01:00 On 02-01-01 at 23:02 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. BTW, list is not the same what queue. >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:* The queue I sent last time, was just simple, with only basic operations. You may add your own fuction, which will give you value of node, without removig it. It may be for example: function Get_Value (Element_Number : Integer; Queue : Queue_Type) return Integer; This function can iterate to specified node in the queue, and return its value without destroying it. >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; > >------ Just as I said, I proposed only basic operations - Add and Remove. You may extend it by provinding another subprograms. >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. If you want to know, how many elements is in queue, you may add another function. In example I sent last time, I was storing number of elements in queue in variable Number_Of_Elements. function Count (Queue : Queue_Type) return Integer is begin return Number_Of_Elements; end Count; Bye, Mike