Define the 3 bolded functions for the following DynIntStack (linked list): class DynIntStack { private: struct Node { int value; // Value in the node Node *next; // Pointer to the next node }; Node *top; // Pointer to the stack top public: DynIntStack() { head = nullptr; } void push(int); //assume this is already defined void removeTop(); // removes the top element without returning it int topValue(); // returns the top element without removing it bool isEmpty() { return head == nullptr; } bool isFull() { return false; } void pushMany(int values[], int n); //add n values from the array };
Define the 3 bolded functions for the following DynIntStack (linked list):
class DynIntStack {
private:
struct Node {
int value; // Value in the node
Node *next; // Pointer to the next node
};
Node *top; // Pointer to the stack top
public:
DynIntStack() { head = nullptr; }
void push(int); //assume this is already defined
void removeTop(); // removes the top element without returning it
int topValue(); // returns the top element without removing it
bool isEmpty() { return head == nullptr; }
bool isFull() { return false; }
void pushMany(int values[], int n); //add n values from the array
};
Hints:
- void removeTop() (hint 3 lines of code)
- int topValue() (hint 1 line of code)
- void pushMany(int values[], int n) (hint 2 lines of code, use a for loop, call another function)
void DynIntStack::removeTop(){
struct Node *temp=top;
top=top->next;
delete temp;
}
int DynIntStack::topValue(){
return top->value;
}
void DynIntStack::pushMany(int values[],int n){
for(int i=0;i<n;i++){
push(values[i]);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 1 images