some assistance with a linked list

N

newtothis

Being new to the use of C++ I have written a linked list program. It
seems to crash after I delete from the list and then add a new node.



Also this is not college homework, I have also looked at various
postings here on the topic. They do not seem to help.



If someone more of an expert than me could please check what I have put
together and make some relivent comment I am happy to post the files to
the program, once I work out how to attache them all.



Thanks
 
D

David White

newtothis said:
Being new to the use of C++ I have written a linked list program. It
seems to crash after I delete from the list and then add a new node.



Also this is not college homework, I have also looked at various
postings here on the topic. They do not seem to help.



If someone more of an expert than me could please check what I have put
together and make some relivent comment I am happy to post the files to
the program, once I work out how to attache them all.

Don't attach any of them. Attachments are not well received in non-binary
newsgroups. Just include the code in your post, preferably the smallest
amount of code that exhibits the problem. Write a small test program that
does nothing but operations on the list, and remove any functions that are
not executed. The smaller the code the more people will have the time to
look at it.

DW
 
N

newtothis

Thanks David.



I would but the program is divided into 3 distinct classes, the list ,
the node and the datacomponent stored in the node. plus the main test
driver program. 7 seperate files



From what I can see I think my code needs some form of cleaning up. That
is where I need some assistance.



It looks as if I am getting some form of stack overflow since i am not
getting rid of old nodes, etc.



The program works if it write it in java or C. I seem to be having some
problems with this in C++.



I am trying to build an event queue, as a llinked list so I really only
want the list and node components when its finished.
 
K

Karl Heinz Buchegger

newtothis said:
Thanks David.

I would but the program is divided into 3 distinct classes, the list ,
the node and the datacomponent stored in the node. plus the main test
driver program. 7 seperate files

And ?

Your problem is a crash when adding a node after you have deleted one.
So all we need to see is the add function and the delete function.
Add a list class which contains only those 2 functions, add a node class
and a main() which calls this 2 functions in that order.
Make sure that this also crashes and ...
.... post

If you don't think you have the time to do this, then I am sorry,
nobody will have the time to wade through your code, analyze it,
figure out where you went wrong and tries to give some advice on
where your mental model is wrong and fix your bugs at the
same time.
 
J

John Villalovos

Being new to the use of C++ I have written a linked list program. It
seems to crash after I delete from the list and then add a new node.



Also this is not college homework, I have also looked at various
postings here on the topic. They do not seem to help.

So is there any reason you aren't just using some of the available STL
containers: vector, list, deques, ect...?

If you are new to C++ then I recommend you use these data structures rather
than creating your own.

John
 
D

David White

newtothis said:
Thanks David.



I would but the program is divided into 3 distinct classes, the list ,
the node and the datacomponent stored in the node. plus the main test
driver program. 7 seperate files

It still shouldn't be too difficult to narrow it down to the problem at
hand. Just copy and paste the linked-list class definition and the add and
delete functions into a single source file. Then add a main() that creates a
list and adds and deletes nodes, and adds them again (whatever causes the
problem). Use a simple, dummy class for the data component if what you have
now is really big and complicated. It shouldn't affect the operation of the
list. Make sure this cut-down version still exhibits the problem and then
post it here. Everyone is happy to help, but few have the time to look
through pages and pages of code.

If the test program does not exhibit the problem, then as a last resort you
can try posting everything (but not in attachments). Someone might be able
to look at it.

DW
 
N

newtothis

Thanks for the various comments on this. It appears the problem is a
little more complex and possible related to stack space. I have run the
program on a different computer, ie different OS but same brand of
compiler and it works fine.

It just does not like windows. Wont run using VC++ either but compiles.

Tanks anyway. still need to clean the coe up a bit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top