Hi. I need help pushing the values onto a stack. Once done, the number of elements should be shown on the first line and the value at the top of the stack on the next line.
Any help would be really appreciated.
#include <iostream>
using namespace std;
class Stack_int
{
private:
struct StackNode {
int value;
StackNode *next;
};
StackNode *top;
int length;
public:
Stack_int(){ top = NULL; length = 0; }
//~Stack_int();
// Stack operations
bool isEmpty() {
if (length == 0)
return true;
else
return false;
}
bool push(int);
// int pop();
int peek() {
return top -> value;
}
int getLength() {
return length;
}
};
/**~*~*
Member function push: pushes the argument onto the stack.
*~**/
bool Stack_int::push(int item)
{
StackNode *newNode;
// Allocate a new node and store num there.
newNode = new StackNode;
if (!newNode)
return false;
newNode->value = item;
// Update links and counter
newNode->next = top;
top = newNode;
length++;