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
Declaration of Variables: Variables are declared as follows: int a; float b;   Assigning value to variables: int a = 100; Declaring and assigning is called ini

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

Prepare aime crossover alert expert adviso Project Description: Need to develop an expert advisor base on aime crossover alert indicator. Skills required is C Programming

Program to draw a circle: int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int midx, midy;    int radius = 100;


.write a program that counts the number of occurrences of the string in the n-th padovan string p(n)   program in java // aakash , suraj , prem sasi kumar kamaraj college

Rules of Inheritance: Private members are not inherited; the members can be accessed only within its class. It cannot be used through the object. Protected members are

Problem : (a) Stacks can be implemented using arrays. Write down the following C or C++ function to (i) create a stack (ii) add an element to a stack (push). (b) Expl

Study the following  class diagram, additional information  and answer  the  questions that follow: MovieTicket movieName: string TicketPrice: doub

wap to print padovan string in c