Node* push(Node* top, int x) {
Node* n = new Node; // Memory allocation
if (!n) { // or (n == NULL)
cout << "Stack overflow" << endl;
return top;
}
n->data = x;
n->next = top;
top = n;
return top;
}
#include <iostream> using namespace std; struct Node { int data; Node* next; }; class Stack { Node* top; public: Stac...
No comments:
Post a Comment