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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,acad772db703a890 X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: Simple Pointer Problem, Help... Date: 1996/05/24 Message-ID: <4o4jf6$akv@newsbf02.news.aol.com>#1/1 X-Deja-AN: 156527773 sender: root@newsbf02.news.aol.com references: <4o2vu9$hdc@catapult.gatech.edu> organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-05-24T00:00:00+00:00 List-Id: gt7693d@acmex.gatech.edu (Daniel J) had trouble debugging a linked list program. Your procedure to add a link to the end of the linked list, AddNodeBack, finds the end of the linked list correctly, but fails to store the pointer to the new node in .Next. You need to keep a pointer to the head of the linked list in a variable (e.g., Num) that doesn't get updated while you grow the list, and you need to pass that *head* of the linked list to AddNodeBack. Your procedure should have a local variable (e.g., Temp) to iterate through the list and find the end, and another local, (SaveTemp) to keep track of the last node so you can set .Next. Here's your corrected procedure: --Purpose: Add a node to the end of a linked list --I changed Point to Head and added Temp and SaveTemp. procedure AddNodeBack (Head : in out NumPtr; Value : in Integer) is Temp : NumPtr := Head; SaveTemp : NumPtr; begin if Head /= null then while Temp /= null loop SaveTemp := Temp; Temp := Temp.Next; end loop; Temp := new NumRecord'(Value, null); SaveTemp.Next := Temp; else Head := new NumRecord'(Value, null); end if; end AddNodeBack; The procedure could be made simpler by eliminating the test for Head /= null, if you're willing to add an unused link to the beginning of the linked list. My Ada Tutor program, available at the WWW and FTP sites below my signature, gives an example. The example is a program that gets integers in any order from the terminal, maintaining a linked list of them in ascending order. When the user types 0, the programs outputs the integers in ascending order. The procedure to add a node is very simple. I hope this helps. - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor