Firstly, the picture doesn't show the connectiveness of the nodes, that is it doesn't show if the node are connected or not, so what are the assumptions?
1) intNode->next points to newNode
2) intNode->prev points to null
3) newNode->prev points to intNode
4) newNode->next points to null
Now if the above assumptions are valid then you can imagine "intNode->next" as just newNode.
hence this statement, newNode->next = intNode->next is just intNode = intNode->next which is a memory leak. You can do similar analysis on the other statement
>> newNode->next = intNode->next After that statement, the following would evaluate to true: newNode == newNode->next . That's as far as it goes. And it would certainly require special attention down the line to avoid problems when trying to delete the linked list (and traversing it in general).
>> intNode->next->prev = newNode After this line, the following would evaluate to true: newNode->prev == newNode , because intNode->next == newNode and thus, intNode->next->prev = newNode <===> newNode->prev = newNode .
So, at the end of both statements, both the newNode->next and newNode->prev would pointing to newNode itself.
Sorry for the unclear problem. This was a review exercise at the end of a chapter and I wasn't sure how the book got it's answer. This is the full question:
At each of the numbered comments, draw the doubly linked list.
intNode = new intNode<int> (10);
newNode = new dnode<int>(20);
newNode->next = intNode->next;
intNode->next->prev = newNode;
newNode->prev = intNode;
intNode->next = newNode; //#1
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...