Implementation of the stack class in c++, C/C++ Programming

Implementation of the Stack class in C++:

How to implement stack class in c++.

int Stack::push(int elem)

{

   if (top < nmax)

   {

      list[top++] = elem;

      return 0;

   }

   else

      return -1;

}

 

int Stack::pop(int& elem)

{

   if (top > 0)

   {

      elem = list[--top];

      return 0;

   }

   else

      return -1;

}

 

void Stack::print()

{

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

      cout << list[i] << "\n";

}

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







Related Discussions:- Implementation of the stack class in c++, Assignment Help, Ask Question on Implementation of the stack class in c++, Get Answer, Expert's Help, Implementation of the stack class in c++ Discussions

Write discussion on Implementation of the stack class in c++
Your posts are moderated
Related Questions
Write a program that counts from 0 to 99 and prints these numbers to the terminal ie it prints 00, 01, 02, 03, 04, 05, ....,99. Graphics 1. Write a program in rPeANUt that

Use 16 digit credit card numbers that contain 15 digits an 1 check digit. The format of the card number consists of the 15 digits followed by the check digit. The check digit is co

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Shell sort - C Program: Write a program to define shell sort. void main() {                  //program for sorting by select sort int a[20],i,k,j,n;   clrscr();

store the name of the political parties and the corresponding votes in two lists of equal length. access the lists is provided by two methods, each of which creates an interator th

Design a game in c: const DODGERS = 0; const GIANTS = 1;   void main(void) {    int scoreboard [2][9];    // An array two rows by nine columns    int team, i

What is Ms dos?

Many modern cryptography algorithms require two numbers that are coprime, or sometimes referred to as relatively prime. Two numbers are coprime if their greatest common divisor is

Is always the default constructor for Fred Fred::Fred()?

: Write a program that prompts the user to enter five digit positive numbers. The program then outputs the digits of the number one digit per line. Eg if the user enters 32456, th