A little bit of a strange implementation, but generally you're on the right track. It is a little tough for us since we don't know what sPtr or newPtr are, but here are some notes:
Code:
if(test != 1) { /*insert new node into appropriate place in list*/
head = *sPtr;
previousPtr = NULL;
check = 0; /*this is used to check if there is at least 1 node with a value*/
while(head != NULL) {
previousPtr = head; /*move through list until the end*/
head = head->nextPtr;
check++; /*increase check to show at least 1 node used*/
}
This is generally correct, though you don't need the check variable. Usually you just check if head is NULL. If it is, you simply set head to point to the new node. If not, you run the above loop.
Code:
if(check > 0){ /*if there exists a node in the list, put new node at the end*/
head = newPtr; /*shouldnt head be pointing to NULL after the loop so this should be adding it to the end?*/
}
No, it wont add it to the end. head just contains an address. Before the assignment here, it contained NULL. Now it contains the same address that newPtr contains. To "link" up your list, you need to point prev->nextPtr to the new node.
Code:
else /*if there are no nodes being used, put a node at the beginning*/
{
newPtr->nextPtr = *sPtr;
*sPtr = newPtr;
}
}
Not sure this is correct. You should be setting the head of the list to point to newPtr, and newPtr->nextPtr to point to NULL, since it's the only element thus far.
EDIT: Looks like Quzah beat me