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

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

write an algorithm for linear search algorithm

3. Write a program to encrypt and decrypt strings of characters using the following ciphers: a) Caesar cipher b) Vigenere cipher c) Matrix transposition cipher Your program shoul

Define Polymorphism? A: Polymorphism let a client to treat di_erent objects in the simialr way even if they were developed from di_erent classes and exhibit di_erent behaviors.

Dynamic Initialization of objects: It is initializing the objects by passing the valued to the constructor from the user input or other means.   Through cin operator a value

A: This will turn o_ "name mangling" for func so that one can connect to code compiled by a C compiler.

Assume that a Binary Search Tree is constructed by repeatedly inserting exact values in to the tree. Argue that the number of nodes examined in searching for a value in the tree is


write a pseudocode algorithm for a program that accepts a number and prints out its reciprocal(1/n) is required.the program should prevent the user from entering zero by asking t