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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d142408257dde54c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-29 11:44:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.esat.net!colt.net!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news11-gui.server.ntli.net.POSTED!not-for-mail Reply-To: "Liddle Feesh" From: "Liddle Feesh" Newsgroups: comp.lang.ada References: Subject: Re: Can someone help me understand this queue package? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <9ZoX7.10133$Zg2.442282@news11-gui.server.ntli.net> Date: Sat, 29 Dec 2001 19:37:51 -0000 NNTP-Posting-Host: 213.105.185.39 X-Complaints-To: abuse@ntlworld.com X-Trace: news11-gui.server.ntli.net 1009654725 213.105.185.39 (Sat, 29 Dec 2001 19:38:45 GMT) NNTP-Posting-Date: Sat, 29 Dec 2001 19:38:45 GMT Organization: ntl Cablemodem News Service Xref: archiver1.google.com comp.lang.ada:18385 Date: 2001-12-29T19:37:51+00:00 List-Id: "Michal Nowak" wrote: > You may even download all zipped files. If you have them, would you mind emailing them to me, since the website is currently down. > >> >Could someone be so kind as to convert the following package into > >> >pseudo-code for me? > >> > >> No :-)). > >> Solution 1. > >> Treat a queue as a simple list (you may abandon Iterators idea for > >> simplicity), with operations Add and Remove. > >> Add is something like Insert at beginning, > >> and Remove is like delete at the end. > > > >Will do... What is Iterators idea? > > "ADA 95: THE CRAFT OF OBJECT-ORIENTED PROGRAMMING" - chapter 11 > (in particular - 11.4) I'll see if that particular section is on Google's Cache. > >> Solution 2. > >> Take paper, pencil and draw what is happening with pointers (access > >> types) during addition and removal (such as on pictures in chapter 11). > >> Than implement it. > > > >Yes, but what >IS< happening with pointers? I'll have a go. > > Ooops, I don't get what you mean by it. Hmm, you create a node, a then > set some variables f access types (pointers) to point you to this node, > and some pointers from this node to point to another node. Some lovely diagrams :) Best viewed in fixed-point font though! > end of queue Beginning of queue > | | > \|/ \|/ > V V > -------------- --------------- ---------------- > | Data | Next|---> | Data | Next |---> | Data | Next | > -------------- --------------- ---------------- > Node 3 Node 2 Node 1 > > Suppose now you add something to the end of the queue. > You create new node (let's call it New_Node) and set its > Next pointer to point to last element in the queue. > > end of queue Beginning of queue > (Tail) (Head) > | | > \|/ \|/ > V V > -------------- --------------- --------------- > | Data | Next|---> |Data | Next |---> | Data | Next | > -------------- --------------- --------------- > Node 3 Node 2 Node 1 > > > -------------- > | Data| Next | > --------------- > New_Node > > New_Node.Next := Tail; > Tail := New_Node; > > So now you have something like this: > > end of queue Beginning of queue > (Tail) (Head) > | | > \|/ \|/ > V V > ------------- ------------ ------------- -------------- > | Data| Next |-->| Data | Next|-->| Data| Next |-->| Data | Next | > ------------- ------------- ------------- -------------- > New node Node 3 Node 2 Node 1 > > > Removal is similar, although you may need to add Prev to node to point for > previous item for convenience (unless you want to go through whole queue to > search for element before the last one). > > So if we remove Node_1 element (Node_2 := Node_1.Prev) > Node_2.next := null; > Head := Node_2; > > Is this what you were looking for? Uh - yes, and I couldn't have asked for a better, more clear explanation. I hope this sits on Google's archive for a long time to come to help out all those other hapless newbies! > >> BTW it looks like a homework or something. Do you want to stay with Ada > >> for a longer time, or just write the program, pass the subject, and > >forget? > > > >I like the principals of ADA - it'll probably be something I'll stick with > >and have to learn. I'm trying to read it as part of my degree; > > Great. So you should know a secret - it is Ada :-)) Another Difficult Addon. or A Dysfunctional Analogy ;) > >of course > >ADA > >is quite a good skill to learn; esp. with the industries in my local area. > > I may envy you that... It's quite common here. Check out www.jobserve.co.uk for Ada - I think this should bring back some interesting reading. > >> However, good luck and don't break down, > > > >I think I'm about to cry... > > Oh, boy, don't joke ;-)) *Grabs some Gin and Tonic* -- Liddle Feesh ' O 0 o <"//>< ' o'^ (Remove UNDERPANTS to reply)