473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem updating linked list

37
Hello all
I have a linked list and a method that inserts certain elements in the link. When going trough the list in the method I make the changes the list is changed as i want, but when i use the list in another function the list is not updated, it contains null components. What can I do in order for my list to remain changed?
this is the functin that modifies the list
Expand|Select|Wrap|Line Numbers
  1. BYTE CheckComponents()
  2. {
  3.   Node *comp=components, *x, *y;
  4.   while (comp!=NULL)
  5.   {
  6.     ..............................
  7.     y = new Node("Telegram", telegram, PLAIN_DESC);
  8.     y->setNext(comp->getNext());
  9.     comp->setNext(y);
  10.     comp=comp->getNext();
  11.  
  12.   }
  13. }
  14.  
can you please tell me what am i doing wrong?
thanks
Sep 25 '07 #1
2 1285
dmjpro
2,476 2GB
Hello all
I have a linked list and a method that inserts certain elements in the link. When going trough the list in the method I make the changes the list is changed as i want, but when i use the list in another function the list is not updated, it contains null components. What can I do in order for my list to remain changed?
this is the functin that modifies the list
Expand|Select|Wrap|Line Numbers
  1. BYTE CheckComponents()
  2. {
  3.   Node *comp=components, *x, *y;
  4.   while (comp!=NULL)
  5.   {
  6.     ..............................
  7.     y = new Node("Telegram", telegram, PLAIN_DESC);
  8.     y->setNext(comp->getNext());
  9.     comp->setNext(y);
  10.     comp=comp->getNext();
  11.  
  12.   }
  13. }
  14.  
can you please tell me what am i doing wrong?
thanks
Show me your full code.
Then I will be able to solve your code.

Kind regards,
Dmjpro.
Sep 25 '07 #2
Dreea
37
I was deleting y variable at the end of the function, that is why the list was truncated in other functions. Now I have another problem... I have pieces of code similar to this one:
Expand|Select|Wrap|Line Numbers
  1.     p2=new Node(x->getComponentName(), cVal, cVal);
  2.     p1->setNext(p2);
  3.     p1=p2;
  4.     p2=NULL;
  5.     delete p2;
  6.  
and in the output window I find the following message signaling i have a memory leak at the line where I allocate memory to p2
program.cpp(1311) : {501} normal block at 0x00435EC0, 56 bytes long.
Data: < [B ^C A%C > F4 5B 42 00 00 5E 43 00 CC CD CD CD 41 25 43 00
{500} normal block at 0x00435F30, 33 bytes long.
Data: < 21 23 4A E3 > 00 32 31 20 32 33 20 34 41 20 45 33 20 00 CD CD
{497} normal block at 0x004359E0, 33 bytes long.
Data: < Telegram > 00 54 65 6C 65 67 72 61 6D 00 CD CD CD CD CD CD

Any idea what am I doing wrong?
Sep 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
10
by: Ben | last post by:
Hi, I am a newbie with C and am trying to get a simple linked list working for my program. The structure of each linked list stores the char *data and *next referencing to the next link. The...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
11
by: bofh1234 | last post by:
Hello, I am having a problem with linked lists. My program is based on a client server model. The client sends some packets of data to the server. The server reads those packets and is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.