Stack operations - c++, C/C++ Programming

Assignment Help:

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";

   }

}


Related Discussions:- Stack operations - c++

Program to track the hours an employee worked , Description: Create a...

Description: Create a program that allows the user to track the hours an employee worked in a week. How much the employee was paid and any extra hours worked (overtime pay).

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Write program to get largest element in array using function, Write a progr...

Write a program to get the largest element in an array using Function? # include int largest(int b[],int); main() { int lar,a[5]={12,2,36,40,5}; lar=largest(a,n); printf("

Explain relational operators, Relational Operators A relational operato...

Relational Operators A relational operator is used to make comparison among two values. All these operators are binary and needs two operands. There are the following relationa

Create a software application, Project Description: Currently seeking so...

Project Description: Currently seeking someone who can create me a software application (google chrome crx file_ that will auto add all shoe sizes to cart directly and if not av

Bus Connection, how to explain working of bus connection

how to explain working of bus connection

Programming C/C++ need a answer, 3. Write a program to encrypt and decrypt...

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

C program to replace every occurrence of in a string, Program is to replace...

Program is to replace every occurrence of in a string: Program is to replace every occurrence of c1 in string with c2 and have function return the no. of replacement int re

C program for the no are in ascending order , #include stdio.h> #include...

#include stdio.h> #include conio.h> #include string.h> void main() {           int i=0,j=0,k=0,l=0;           int a[3][3],temp[3][3];           clrscr();

Decode the Code, Smugglers are becoming very smart day by day. Now they hav...

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

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd