Switch to full style
For C/C++ coders discussions and solutions
Post a reply

Code of stack

Sun May 25, 2008 5:08 pm

Here is the stack.h ( The stack header file )
cpp code
#include "stack.h"

Stack::Stack()
{
topIndex=-1;
}
void Stack::push(StackElementType item)
{
++topIndex;
assert(topIndex < maxStackSize);
stackArray[topIndex]=item;
}

StackElementType Stack::pop()
{
assert(topIndex>=0);
int returnIndex(topIndex);
--topIndex;
return stackArray[returnIndex];
}

bool Stack::isEmpty()
{
return topIndex==-1;
}


And here is the implementation file :

cpp code
#include "stack.h"

Stack::Stack()
{
topIndex=-1;
}
void Stack::push(StackElementType item)
{
++topIndex;
assert(topIndex < maxStackSize);
stackArray[topIndex]=item;
}

StackElementType Stack::pop()
{
assert(topIndex>=0);
int returnIndex(topIndex);
--topIndex;
return stackArray[returnIndex];
}

bool Stack::isEmpty()
{
return topIndex==-1;
}




Post a reply
  Related Posts  to : Code of stack
 Stack using java     -  
 i want code for connecting mobile and pc can u send me code     -  
 Freeman chain code algorithm code     -  
 asking for code     -  
 code     -  
 error in code     -  
 NotePad C# code     -  
 What will be validation for Zip code ?     -  
 Get IP address code     -  
 XML Paging Code     -  

Topic Tags

C++ Data Structures