#include <stdio.h> struct stack { char space[512]; int top; }; struct stack stack = { { 0 }, 0 }; int isempty(){ return stack.top == 0; } int isfull(){ return stack.top == 512; } void push(char val) { stack.space[stack.top] = val; stack.top++; } char pop() { stack.top--; return stack.space[stack.top]; } int main() { if (!isfull()) push('a'); if (!isfull()) push('b'); if (!isfull()) push('c'); while (!isempty()) putchar(pop()); return 0; }
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; class Stack { public : void init(); bool isEmpty(); bool isFull(); void push(int data); int pop(); private: int space[1024]; int top; }; void Stack::init() { memset(space, 0, sizeof(space)); top = 0; } bool Stack::isEmpty() { return top == 0; } bool Stack::isFull() { return top == 1024; } void Stack::push(int data) { space[top++] = data; } int Stack::pop() { return space[--top]; } int main() { Stack s; s.init(); if (!s.isFull()) s.push(10); if (!s.isFull()) s.push(20); if (!s.isFull()) s.push(30); if (!s.isFull()) s.push(40); if (!s.isFull()) s.push(50); while (!s.isEmpty()) cout << s.pop() << endl; return 0; }