Computers and Technology

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;
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 10:20, chonawilson4
Suppose there is a relation r(a, b, c) with a b+-tree index with search keys (a, b).1. what is the worst-case cost of finding records satisfying 10 < a < 50 using this index, in terms of the number of records n1, retrieved and the height h of the tree? 2. what is the worst-case cost of finding records satisfying 10 < a < 50 and 5 < b < 10 using this index, in terms of the number of records n2 that satisfy this selection, as well as n1 and h defined above? 3. under what conditions on n1 and n2, would the index be an efficient way of finding records satisfying the condition from part (2)?
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, abdulbasharee99
In the context of the box model, what is the difference between a margin and a padding? a. a padding lies outside a box border, while a margin lies inside it. b. a padding lies inside a box border, while a margin lies outside it. c. a padding can be adjusted independently, while a margin depends on the size of its box. d. a padding depends on the size of its box, while a margin can be adjusted independently.
Answers: 3
image
Computers and Technology, 24.06.2019 15:30, taylorpayne525p8qxky
What is not a type of text format that will automatically be converted by outlook into a hyperlink?
Answers: 1
image
Computers and Technology, 25.06.2019 20:30, dtovar9911
The spreadsheet ends after you reach column z and row 99. true or false
Answers: 1
Do you know the correct answer?
C program, Assign negativeCntr with the number of negative values in the linked list, including the...

Questions in other subjects:

Konu
Mathematics, 20.09.2020 03:01