Below is the usage for the IntNode_GetNth, IntNode_PrintList, and IntNode_SumList functions.
C
IntNode* IntNode_GetNth(IntNode* firstNode, int pos) {
if (pos < 1 || firstNode == NULL) {
return NULL;
}
IntNode* curNode = firstNode;
for (int i = 1; i < pos; ++i) {
curNode = curNode->nextNodePtr;
if (curNode == NULL) {
return NULL;
}
}
return curNode;
}
void IntNode_PrintList(IntNode* firstNode) {
if (firstNode == NULL) {
return;
}
IntNode* curNode = firstNode;
while (curNode != NULL) {
IntNode_PrintNodeData(curNode);
curNode = curNode->nextNodePtr;
}
}
int IntNode_SumList(IntNode* firstNode) {
if (firstNode == NULL) {
return 0;
}
int sum = 0;
IntNode* curNode = firstNode;
while (curNode != NULL) {
sum += curNode->dataVal;
curNode = curNode->nextNodePtr;
}
return sum;
}
The above code functions do complete the given program and perform the necessary operations on the linked list.