delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/18/03:31:48

From: dmt AT bigfoot DOT com (Jeff W./DMT)
Newsgroups: comp.os.msdos.djgpp
Subject: Linked Lists?
Date: Sat, 18 Apr 1998 06:23:14 GMT
Organization: ZipLink -- America's Hottest ISP
Lines: 35
Message-ID: <35384655.75520@news.ziplink.net>
NNTP-Posting-Host: chi-ip-1-24.ziplink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I know how to write one in Pascal, but I'm having some trouble in C++.
My basic problem is that I have a function, InsertNode(ListNode *List,
i) that adds a new node with data value I to the end of a current
list.  Here is the code:

void InsertNode(ListNode *List, int i)
{
 ListNode *Temp;

 if (List == NULL)
   {
    Temp = (ListNode *)malloc(sizeof(ListNode));
    Temp->data = i;
    Temp->Next = NULL;
    List = Temp;
   }
 else
   InsertNode(List->Next, i);

}

Everything works fine, however, when the function exits, the variable
that I had originally passed to InsertNode remains unchanged.  How
would I do this??
 --Jeff W.

 "The finding of DMT in normal human body fluids
 opens up interesting moral and legal questions.
 Since DMT is illegal, as is 'any substance, compound
 or mixture' containing DMT, it would seem that we
 are all guilty of possesion of a controlled substance"
 -Jonathon Ott

 My weird, trippy page:
 http://www.geocities.com/SunsetStrip/Alley/3450/index.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019