Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python

C++


JAVA
PHP
SQL
Assignments

Stack


stack.h

//-----------------------------------------------------------------------
// stack.h
//-----------------------------------------------------------------------
// Stack class
// Written by Charles A. Cusack, January 2000
//
// This is a class for the stack data structure.
// It is implemented with a simple array.
//
//-----------------------------------------------------------------------
class Stack {

private:                                   // The data used for the stack 

int *stack;       // The stack elements will be stored here
int size;         // The capacity of the stack
int top;          // The top of the stack

public:                                           // The stack operations 

Stack(int s=100);                 // The constructor initialize the stack
~Stack();                    // The destructor frees the allocated memory
int Push(int v);       // Place item on the stack. Return 1 if successful
int Pop();                // Remove top of the stack and return its value 
                          // Return -1 if unsuccessful
int Empty();                            // Return 1 if empty, 0 otherwise
int Full();                              // Return 1 if full, 0 otherwise
};
//-----------------------------------------------------------------------