467,923 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

some assistance with a linked list


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
--
Posted via http://dbforums.com
Jul 19 '05 #1
  • viewed: 4657
Share:
6 Replies
"newtothis" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...

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

Jul 19 '05 #2

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.
--
Posted via http://dbforums.com
Jul 19 '05 #3


newtothis wrote:

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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #4
In article <35****************@dbforums.com>,
newtothis <me*********@dbforums.com> wrote:

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
Jul 19 '05 #5
newtothis <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...

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

Jul 19 '05 #6

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
--
Posted via http://dbforums.com
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jeffrey Silverman | last post: by
11 posts views Thread by C++fan | last post: by
5 posts views Thread by Dream Catcher | last post: by
5 posts views Thread by John N. | last post: by
6 posts views Thread by Steve Lambert | last post: by
12 posts views Thread by joshd | last post: by
13 posts views Thread by B. Williams | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.