1. How can I view dynamically created memory? All elements of the linked list won't and do not show up in the 'watches' debugging window. (Code::blocks is my IDE)
2. When I run this program, printNumberInList works fine. For removeFromList, on the otherhand, it loops for infinity and never reaches the printNumberInList function - even though they both loop on the same principal.
Consider lines 41 and 43. If you delete firstList at line 41, firstList no longer points to anything valid. Yet, at line 43, you try to reference firstList->next_myList.
I see some of the problems in the existing code, and I forgot to include that neither of my if statementse are ever triggered. My question is why they act differently, in that case, when they are essentially the same loop?
Also, the conditions on lines 33 and 37 are the same, so you set before to firstList and then change it to after (or firstList->next_myList) pretty much immediately afterwards.
The names make me think you're heading in the right direction.,,
But line 28, where you subtract 1 from the value you want to delete, does not make any sense to me. What happens if you've already deleted nodes and the numbers are no longer contiguous?
How does your function handle deleting the first node in the list?
How can you join the node before the one you're deleting up with the one after it?
Andy
PS Your struct myList is what would usually be called something like myListNode or just myNode.
You don't need to previous_myList member because you don't use it.
Lines 33-38 could go above line 31. There's no reason for that logic to be inside the loop.
removeFromList() removes the n'th element of the list (where n is the second parameter). Is that what you really want, or should it remove the node whose value is n?
I've made some revisions, and I think I am on my way to solving this. Thanks for your help in advance. Can anyone explain to me why my delete statements in my removeFromList function are causing my list to break? My printNumberInList function loops indefinitely with random numbers of memory, but will print the numbers correctly up until a revision is made... this is the output of the above example with 1 as the steps argument:
4 (I thought I deleted 4?)
-random number
-random number
-random number (for infinity)
Lots of love to he whom lets me continue my progress and learning. Some things I need to understand:
1. Why isn't my memory linking up right? With COUT statements I can see that the pointers are pointing to their next node and previous node correctly... so theoretically why is this not working?
2. In my printNumberInList function, why does it work multiple times? I would expect that the second time through firstList would now = NULL, but for some reason I can declare and use that function multiple times!!!
I recommend that you remove the previous_myList member. In other words make this a singly linked list instead of a doubly linked list. Doubly linked lists take extra work to maintain the pointers. You're probably better off getting the singly linked list working right first.