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

Study the given hierarchical class diagram and additional information, and answer the questions that follow: Sale Company: string unitPrice: double

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

implement two stacks in one array A[1...n] in such a way that neither stack overflows unless the total number of elements in both stacks together is n. For this you need to produce

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

In this sub-task will you implement three functions for the final three function prototypes that will do exactly the same as the three functions that you have just written. This ti

Q: How the compiler arranges the several sections in the executable image? A: The executable contained following sections: 1.      Data Section (initialized data variable sec

Problem Implement a class called employee that contains name, employee number and department code. Include a member function getdata() to get data from user and store it in the

First line starts with T, number of test cases. Each test case T contains a necklace (N).

A: Memory that has no pointer pointing to it and there is no method to delete or reuse this memory(object), it causes Memory leak. { Base *b = new base(); } Out of this