subject

C program, Assign negativeCntr with the number of negative values in the linked list, including the list head. #include
#include
typedef struct IntNode_struct {
int dataVal;
struct IntNode_struct* nextNodePtr;
} IntNode;
// Constructor
void IntNode_Create(IntNode* thisNode, int dataInit, IntNode* nextLoc) {
thisNode->dataVal = dataInit;
thisNode->nextNodePtr = nextLoc;
}
/* Insert newNode after node.
Before: thisNode -- next
After: thisNode -- newNode -- next
*/
void IntNode_InsertAfter(IntNode* thisNode, IntNode* newNode) {
IntNode* tmpNext = NULL;
tmpNext = thisNode->nextNodePtr; // Remember next
thisNode->nextNodePtr = newNode; // this -- new -- ?
newNode->nextNodePtr = tmpNext; // this -- new -- next
}
// Grab location pointed by nextNodePtr
IntNode* IntNode_GetNext(IntNode* thisNode) {
return thisNode->nextNodePtr;
}
int IntNode_GetDataVal(IntNode* thisNode) {
return thisNode->dataVal;
}
int main(void) {
IntNode* headObj = NULL; // Create intNode objects
IntNode* currObj = NULL;
IntNode* lastObj = NULL;
int i; // Loop index
int negativeCntr;
negativeCntr = 0;
headObj = (IntNode*)malloc(sizeof(IntNode)); // Front of nodes list
IntNode_Create(headObj, -1, NULL);
lastObj = headObj;
for (i = 0; i < 10; ++i) { // Append 10 rand nums
currObj = (IntNode*)malloc(sizeof(IntNode));< br /> IntNode_Create(currObj, (rand() % 21) - 10, NULL);
IntNode_InsertAfter(lastObj, currObj); // Append curr
lastObj = currObj; // Curr is the new last item
}
currObj = headObj; // Print the list
while (currObj != NULL) {
printf("%d, ", IntNode_GetDataVal(currObj));
currObj = IntNode_GetNext(currObj);
}
printf("\n");
currObj = headObj; // Count number of negative numbers
while (currObj != NULL) {
/* Your solution goes here */
currObj = IntNode_GetNext(currObj);
}
printf("Number of negatives: %d\n", negativeCntr);
return 0;
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:00
Hyperactive media sales has 10 windows 7 laptop computers used by sales-people in the organization. each laptop computer has several customized applications that are used during the sales process as well as customer relationship management software. all of the applications on the laptops are difficult to configure and have large data files. if all of the laptops have current hardware, what is the easiest way to install windows 10 on them?
Answers: 1
question
Computers and Technology, 23.06.2019 00:10
My has been slow anyone else’s ?
Answers: 1
question
Computers and Technology, 23.06.2019 20:00
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
C program, Assign negativeCntr with the number of negative values in the linked list, including the...
Questions
Questions on the website: 13722362