The program is mostly filled out, you will only be responsible to complete the sections labeled "TODO", there are 4. Do not change or remove any existing code, that's what was given to us.

1 answer below »
The program is mostly filled out, you will only be responsible to complete the sections labeled "TODO", there are 4. Do not change or remove any existing code, that's what was given to us.
Answered Same DayMar 23, 2021

Answer To: The program is mostly filled out, you will only be responsible to complete the sections labeled...

Arun Shankar answered on Mar 24 2021
155 Votes
/* Lab 4 Due 6pm Tuesday 23 March 2021
* UWEC Spring 2021
* Name:
*
*/
#include
#include
// Now, `Data` will be an alias for `double`
// This can be changed with minimal
precipiated changes required.
typedef double Data;
struct node{
Data value;
struct node *next; //HAS to be a pointer! To avoid infinitely recursive type defn.
};
//Full type name is `struct node`. For convenience, lets re-alias as
typedef struct node Node;
//as `Node`
//Combine typedef and struct stack definition
typedef struct stack {
Node *topNode;
unsigned size;
} Stack;
//Thus, `struct stack` is aliased as `Stack`
//Serves as a "partial" constructor, in the sense that only
// default initialization happens.
// Does NOT allocate the memory for the Stack
//Precondition: Stack *stack points to memory that has already been dynamically allocated.
void initStack( Stack *stack ){
stack->topNode = NULL;
stack->size = 0;
}
//Precondition: toPrint points to validly allocated memory
void printStack(Stack *toPrint){
Node *currentNode = toPrint->topNode;
while(currentNode != NULL){
printf("%lf\n",currentNode->value);
currentNode = currentNode->next;
}
printf("Bottom of stack reached.\n");
}
/*
This method should return how many Nodes are in the Stack pointed to by stack.
Precondition: Stack *stack points to validly allocated memory for a Stack instance.
*/
unsigned getStackSize( Stack *stack )
{
return stack->size;
}
/*
Precondition: Stack *stack points to validly allocated memory for a Stack instance.
Postcondition:
1) This method should create a new Node containing data,
The new Node MUST be dynamically allocated using malloc()
(Your job: to understand why...in terms of variable scope)
2) add (or "push") this new Node to the "top" of the Stack pointed to by stack.
3) The stack->size should increment
If everything was successful, return a pointer to the new Node. If it was unsuccessful, return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here