Stack operations - c++, C/C++ Programming

Stack operations - C++:

Write a program to define basic stack operations in c++.

int Stack::push(int elem)

{

   int m = getmax();

   if (top < m)

   {

      put_elem(elem,top++);

      return 0;

   }

   else

      return -1;

}

 

int Stack::pop(int& elem)

{

   if (top > 0)

   {

      get_elem(elem,--top);

      return 0;

   }

   else

      return -1;

}

 

void Stack::print()

{

   int elem;

 

   for (int i = top-1; i >= 0; --i)

   {  // Print in LIFO order

      get_elem(elem,i);

      cout << elem << "\n";

   }

}

Posted Date: 10/19/2012 3:06:20 AM | Location : United States







Related Discussions:- Stack operations - c++, Assignment Help, Ask Question on Stack operations - c++, Get Answer, Expert's Help, Stack operations - c++ Discussions

Write discussion on Stack operations - c++
Your posts are moderated
Related Questions
A: The procedure of encoding the parameter types along with the function/method name into a unique name is called as name mangling. The inverse procedure is called demangling. F

F u nction overloading: Functions can be defined with same name.  Depending upon the type of argument passed the function will perform.  This is known function overloading

C Programming and Data Structures 1. Define and explain flow chart with an example. 2. Write an algorithm to print all even numbers in descending order and draw the flowcha

real time application of b tree


#I have assignment c with unix thread multiplication program ..

In this worksheet you are asked to write three classes in C++: Lecture class, Course class and University class. The classes relate to each other in the way that a Course has many

Project Description: Currently seeking someone who can create me a software application (google chrome crx file_ that will auto add all shoe sizes to cart directly and if not av

Project Description: Online game development Online Live Baccarat Game is needed - client program. - server program(IOCP or ect..). - web program(ASP or PHP or etc..

implementation of the power and factorial in programs