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,a676349b69fa778f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-12 09:44:05 PST Path: supernews.google.com!sn-xit-03!supernews.com!hermes.visi.com!news-out.visi.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!btnet-peer1!btnet-peer0!btnet!news5-gui.server.ntli.net!ntli.net!news2-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" Newsgroups: comp.lang.ada References: <79Dh6.10732$zz4.264993@news2-win.server.ntlworld.com> Subject: Re: Help: my list adt is broken X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: Date: Mon, 12 Feb 2001 17:33:01 -0000 NNTP-Posting-Host: 62.252.148.68 X-Complaints-To: abuse@ntlworld.com X-Trace: news2-win.server.ntlworld.com 981999195 62.252.148.68 (Mon, 12 Feb 2001 17:33:15 GMT) NNTP-Posting-Date: Mon, 12 Feb 2001 17:33:15 GMT Organization: ntlworld News Service Xref: supernews.google.com comp.lang.ada:5179 Date: 2001-02-12T17:33:01+00:00 List-Id: Hi, it's me again!!! This isn't about a broken ADT as such, more of a problem i'm having visualising and implementing an operation. I want to be able to swap two elements on the same list (if you don't use the same list it's your problem basically, since to guarantee this i would have to walk the list). The problem is i can't get it to work. I've been testing the possible conditions for failure, and my solution fails on the first -- when you swap head and tail (it will fail if i swap the head or tail with any position in the list, me thinks). I would like to know how to do it. I've been trying this for ages, and have loads of wee diagrams to prove it. Since i'm implementing a doubly linked list i have to update the next/prev for each position given, but somewhere along the lines it get's screwed up. I tried two different solutions. The first would move the tail to the head position the rest of the list would be gone (since the new head wasn't pointing to the rest of the list). My second solution raised a constraint error. This i think was caused by something along these lines p1.prev.next := p2; -- can't do for head since p1.prev is null; p2.next.prev := p1; -- similar thing here. I know what the problems are. I thought combining both the solutions for these might have worked. Alas, it didn't, but maybe it's just me. {next time i do something like this i'm gonna use sentinels!} I'd be grateful for anyones assistance with this. These are my data structures (item is generic) > -- incomplete definition; > -- > type node; > -- type representing position in list; > -- > type list_position is access node; > -- a type representing a node in the > -- list; > -- > type node is record > data : item; > next : list_position; > prev : list_position; > end record; > -- a type represting the list; > -- > type list is record > size : natural; > head : list_position; > tail : list_position; > end record; and this is the spec of the swap routine > -- swap two positions in a list; > -- > -- will raise > -- 1. empty_list_error if list empty; > -- 2. position_error if either positions is > -- invalid; > -- > procedure swap (p1, p2 : in out list_position; > l : in out list ); thanks (yet again), Chris Campbell p.s. i'm not being lazy, i just can't work out what to do. (i don't even know if i'll ever have the need to swap two positions about!!!).