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
Addition of array elements: #define rows 3 #define cols 3 void main() {                 int i=0,j=0,sum=0;                 int arr[rows][cols];

Project Description:  LOOKING TO DEVELOP A ONLINE POKER Web Application. WEBSITE WILL BE DEVELOPED OVER THE NEXT 6 MONTHS Duration & WILL REQUIRE FULL SOFTWARE CODING OF WEB

A PROGRAM TO CALCULATE AREA OF TRIANGLE


Write a program that predicts users’ age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/she is younger or older than G (an initial gues

It is a class defined in the scope of a function _ any function, whether a member functions or a free function. For instance: // Example : Local class // int f() { c

In the Byteland country a string "s" is said to super ascii string if and only if count of each charecter in the string is equal to its ascci value in the byteland country ascii co

Write three functions in C or C++: one that declares a large array statically, one that declares the same large array on the stack, and one that creates the same large array from t


Program for Memory Optimization of C / OpenCL Code Project Description: This is possibly a very simple project for someone with an excellent knowledge of C and OpenCL. That,