Hi
but why do i need a delete and new node 1:1 ratio? |
Otherwise you leak memory. Call delete when you are finished with the resource, this might as late as at the end of
main()
but could be elsewhere - for example if you remove a node.
and im not sure but did you happen to get an error of a dangling pointer on line 76 |
I compiled using the gear icon at the top right of your code with all the warning levels turned on. Only had the warnings I posted. But you obviously have other errors, can you post them here exactly as shown?
Have you fixed up the other things I mentioned?
Have you tried a debugger? It is often the easiest way, provided you have an executable program.
I notice you have
NULL
everywhere, that might cause problems:
NULL
is 0, but you are comparing it to pointers. Use
nullptr
Also, you appear to allocate memory with
new
, but don't initialise anything associated with that pointer. Line 36 to 41 for example.
And you seem to have uninitialised variables everywhere.
You have these global pointers:
countNode*head, *prev, *tail, *current;
But these local ones inside
storeData
countNode*current, *previous, *tail, *temp;
I find that confusing, another good reason not to have global data. If you want to use the global ones, pass them to the function as argulments.
When you get to
EvenData
the global ones are being used, not related to the other ones.
Anyway, I hope this helps - but I think you hav quite a bit to do to fix things up :+)