P
Peter
The way I'm reading the following fragments is, The function call load()
passes a pointer startPtr which I believe is to be the pointer to the head
of the list " Is this correct".
Next: In the line if(previousPtr == NULL) if True the list is EMPTY "Is this
correct" so the new node "newPtr" is inserted and
newPtr->nextPtr is pointed to the head pointer "*sPtr" and the head pointer
"*sPtr" is then pointed to the new node newPtr. "Is this correct"
The head pointer points to the first node or is NULL at all times "is this
correct"
If complete code is required to understand my request say so and I'll post
the main() and load() function including the header file that contains the
structure etc.
Thank you
/* fragment from main() call to load function*/
LISTNODEPTR startPtr = NULL;
load(&startPtr, item, posn);
/* fragment form load() function*/
LISTNODEPTR load (LISTNODEPTR *sPtr, const char *value, int index)
LISTNODEPTR newPtr, previousPtr, currentPtr;
while(currentPtr != NULL && index >= currentPtr->position)
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
}
if(previousPtr == NULL)
{
newPtr->nextPtr = *sPtr;
*sPtr = newPtr;
}
else
{
previousPtr->nextPtr = newPtr;
newPtr->nextPtr = currentPtr;
}
passes a pointer startPtr which I believe is to be the pointer to the head
of the list " Is this correct".
Next: In the line if(previousPtr == NULL) if True the list is EMPTY "Is this
correct" so the new node "newPtr" is inserted and
newPtr->nextPtr is pointed to the head pointer "*sPtr" and the head pointer
"*sPtr" is then pointed to the new node newPtr. "Is this correct"
The head pointer points to the first node or is NULL at all times "is this
correct"
If complete code is required to understand my request say so and I'll post
the main() and load() function including the header file that contains the
structure etc.
Thank you
/* fragment from main() call to load function*/
LISTNODEPTR startPtr = NULL;
load(&startPtr, item, posn);
/* fragment form load() function*/
LISTNODEPTR load (LISTNODEPTR *sPtr, const char *value, int index)
LISTNODEPTR newPtr, previousPtr, currentPtr;
while(currentPtr != NULL && index >= currentPtr->position)
{
previousPtr = currentPtr;
currentPtr = currentPtr->nextPtr;
}
if(previousPtr == NULL)
{
newPtr->nextPtr = *sPtr;
*sPtr = newPtr;
}
else
{
previousPtr->nextPtr = newPtr;
newPtr->nextPtr = currentPtr;
}