Advertisement

Linked Lists Problems

Started by June 04, 2000 05:27 PM
2 comments, last by Sponge99 24 years, 6 months ago
I'm trying to create a linked list with structs..for example

struct LL { char data; LL *next; LL *prev; }*test;
and then I want to create a function to add a new "list" to it. Like update the next...so I do this:

LL *UpdateLL(char what) { LL *updatee; updatee->data = what; test->next = updatee; return test; }
But it doesn't do it! I just changes ALL the 'data' to what ever the 'what' was. What I am I doing wrong? Please help! Dare wa neko o koroshiteimasuka? (Ha! Learn Nihongo!) Edited by - sponge99 on 6/4/00 5:29:12 PM
"Now watch as I run away in a womanly fashion." - Batman
The "updatee" pointer is unknown.
You have to locate your mem dynamicly (new, malloc, LocalAlloc)

Try something like this:
LL *UpdateLL(char what){LL *updatee;updatee = malloc(sizeof(LL));updatee->data = what;test->next = updatee;return test;} 


Don''t forget to free the mem when you''re done (delete, free, LocalFree);

Advertisement
1) When UpdateLL(char what); returns, LL *updatee is deallocated.
2) I don''t understand: "It just changes ALL the ''data'' to what ever the ''what'' was."
Thanks a lot. I didn''t know you had to malloc stuff. Thanks again.


Dare wa neko o koroshiteimasuka? (Ha! Learn Nihongo!)
"Now watch as I run away in a womanly fashion." - Batman

This topic is closed to new replies.

Advertisement