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
What is the difference between JavaScript and PHP? The difference lies with the execution of languages. PHP is server side scripting language, which means that it cannot intera

find area under the curve y=f(x) between x=a &y=b integrate y=f(x)

WHAT IS CGI?

Both malloc & new functions are utilized for dynamic memory allocations & the basic difference is: malloc need a special "typecasting" while it allocates memory for eg. if the poin

removing jewel from a necklace

E v o l u t i o n of Software: In the past stage of programming the software's were developed in Machine language Using binary numbers 1's and 0's.  Later it convert


Aim: To implement a program for following string operations: Length of String. String Concatenation. Substring (provide start index and length) Find character a

how to use nested loop of for in array