Question: #include using namespace std; struct Node { int data; struct Node * next; } ; Node * push ( Node * top , int data
#include
using namespace std;
struct Node
int data;
struct Node
next;
;
Node
push
Node
top
int data
Node
newNode
new Node;
newNode
data
data;
newNode
next
NULL;
if
top
NULL
top
newNode;
else
newNode
next
top;
top
newNode;
return top;
int top
Node
top
return top
data;
int pop
Node
top
if
top
NULL
Node
temp
top;
int x
top
data;
or int x
temp
data;
top
top
next;
delete temp;
return x;
else
return
;
void printStack
Node
top
if
top
NULL
Node
cur
top;
while
cur
NULL
cout
cur
data
;
cur
cur
next;
cout
endl;
Node
valueCheck
Node
stackTop
return stackTop;
int main
struct Node
myStackTop
NULL;
myStackTop
push
myStackTop
;
myStackTop
push
myStackTop
;
myStackTop
push
myStackTop
;
myStackTop
push
myStackTop
;
myStackTop
push
myStackTop
;
printStack
myStackTop
;
myStackTop
valueCheck
myStackTop
;
printStack
myStackTop
;
return
;
In class, you were given the source code for building a stack data structure. You are given this
source code assigncpp but it misses the implementation of the "valueCheck" function. You are
asked to provide the implementation of this function as described below.
The "valueCheck" receives the top pointer of a stack and updates the stack by removing all
elements whose values are a multiple of After that, the function returns top pointer of the stack
after being modified.
Hints:
For implementing the "valueCheck" function, you should pop all values in the given stack
into a temporary stack. While popping each value from the given stack, you can check if the
value should be retained ie not multiple of After that, you can pop all values in the
temporary stack and push them back to the original stack.
Example values that are multiple of are and The value is a multiple of if
it divisible by and the remainder of the division is
The following screenshot shows the excepted output of code after providing the implementation of
the "valueCheck" function.
Import Notes:
You are NOT allowed to change the parameters and return value data type for the
"valueCheck" function.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
