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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f32236e7e55b02e0 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: Ada Queue Date: 2000/04/07 Message-ID: #1/1 X-Deja-AN: 608609409 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <38eca724@news.hamilton.edu> X-Trace: news.demon.co.uk 955259087 nnrp-03:8041 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada X-Complaints-To: abuse@demon.net Date: 2000-04-07T00:00:00+00:00 List-Id: "Joseph T." writes: > Can anyone corroborate why I chose to make this enqueue function using the > passed pointer to Q instead of the temp pointer to loop through the queue? > Any suggestions, ideas, compliments, critiques are greatly appreciated. > Please help. > > procedure Enqueue(Q: in out Queue; E : Element_type) is > New_Queue : Queue; > > begin > if Q /= null then > New_Queue := Q; > while Q.Rest /= null loop > Q := Q.Rest; > end loop; > Q.Rest := new QueueNode; > Q := Q.Rest; > Q.Data := E; > Q.Rest := null; > Q := New_Queue; > else > Q := new QueueNode; > Q.Data := E; > Q.Rest := null; > end if; > end Enqueue; Personally I don't think you should mess with the parameter like this. The temporary variable is the one you should use for traversing the Queue to find its end. procedure Enqueue(Q: in out Queue; E : Element_type) is begin if Q /= null then declare Last : Queue := Q; begin while Last.Rest /= null loop Last := Last.Rest; end loop; Last.Rest := new QueueNode'(Data => E, Rest => null); end; else Q := new QueueNode'(Data => E, Rest => null); end if; end Enqueue;