| fcanto (6) | |
|
My teacher gave me this code but I don't know exactly what the code is doing: newPtr->nextPtr = tempPtr->nextPtr; I was asking if someone could please explain this code to e so i can understand it better. | |
|
Last edited on
|
|
| kevinkjt2000 (224) | |
|
What variable type is newPtr and tempPtr? Do they have a structure definition or is there a class definition? Can you give the context of when this code is executed? | |
|
|
|
| pogrady (411) | |
|
This looks to be part of an iteration program designed to add or remove a node in some sort of data structure. There is a pointer that holds another pointer that is being assigned the address of a pointer that is being pointed to by another pointer. Without the full code its difficult to decipher. | |
|
|
|
| fcanto (6) | |
|
ListNode <NODETYPE> *tempPtr = firstPtr; for (int i =0; i< n -1 ;i++) tempPtr= tempPtr ->nextPtr; newPtr->nextPtr = tempPtr->nextPtr; tempPtr->nextPtr = newPtr; more of the code | |
|
|
|
| chipp (506) | |||
from my opinion:firstPtr and newPtris Listnode type / class.
this simply assign the member of tempPtr i.e. nextPtr to the newPtr member (nextPtr). and so more alike...note: learn class and pointer CMIIW | |||
|
|
|||
| kevinkjt2000 (224) | |
| Looks to me like it is inserting a new node at index n-2. So if there were n nodes in the list, then the code would insert newPtr as the second to last element in the list. | |
|
Last edited on
|
|