Stacks: Epublicist - Ca © 2007, 2008, 2009
Stacks: Epublicist - Ca © 2007, 2008, 2009
Code Example:
myStack s;
push( s, 10 );
#define STACKSIZE 10
#define false 0
#define true 1
// Global Variables
static int stackTop = 0;
static int stack[STACKSIZE];
void main(){
push( 10 );
push( 7 );
push( 3 );
void push(int x)
{
if( isFull() != true )
stack[stackTop++] = x;
else return;
}
int pop( )
{
if( isEmpty() != true )
return stack[--stackTop];
else return 0;
}
int isEmpty(){
if( stackTop == 0 )
return true;
else return false;
}
int isFull(){
if( stackTop == STACKSIZE )
return true;
else return false;
}
ePublicist.ca © 2007, 2008, 2009
Anatomy of a Data Structure
Three components:
• Internal variables
• Necessary (public) functions
• Ancillary (private) helper functions
In C/C++ these are found:
• Internal variables (and prototypes) are defined in the
header files .h
• The definition of what the functions do is defined in
the .c or .cpp
• The actual use of the structure and functions is in
main()
Videos
• http://www.youtube.com/watch?v=gYxmm79zxTQ