C + + simple implementation of pressure stack out of stack

Source: Internet
Author: User


/**********************************************************************   * Copyright (c) 2015,wk Studios * Filename:  stack.h   * compiler:gcc,vs,vc6.0  Win32   * AUTHOR:WK   * time:2015 3 29 ******************* /#include <iostream>using namespace Std;const int size= 10;class stack{private:    int stck[size];//array for storing data    int tos in stack;       Stack top position (subscript of Array) public:stack (); void push (int ch); The function declaration presses the data into the stack fuction    int  pop ();       Declares that data is popped from the stack fuctionvoid showstack (); Declare display stack data function};

/**********************************************************************   * Copyright (c) 2015,wk Studios * Filename:  stack.cpp  * compiler:gcc,vs,vc6.0  Win32   * AUTHOR:WK   * time:2015 3 29 ***************** /#include "stack.h"    //constructor, implementation of the initialization stack Stack::stack () {   tos=0;   stck[size]=0;}   The implementation of the data function pushed into the stack void stack::p ush (int ch) {   if (tos==size)   {      cout<< "stack is full!\n";  return;   }   Stck[tos]=ch;   tos++;   cout<< "You had pushed a data into the stack!\n";}  The implementation of the data function is popped from the stack int stack::p op () {   if (0==tos)   {     cout<< "stack is empty!\n"; return 0;      }  tos--;  return Stck[tos];} Implementation of functions that display data in the stack void Stack::showstack () {  cout<< "the content of stack:\n";  if (0==tos)  {    cout<< "the Stack has no data!\n"; return;  }  for (int i=tos-1;i>=0;i--)  {    cout<<stck[i]<< ';     }   cout<< ' \ n ';}

/********************************************************************** * Copyright (c) 2015,wk Studios * Filename:ma In.cpp * compiler:gcc,vs,vc6.0 Win32 * AUTHOR:WK * time:2015 3 29 ************************************************  /#include "stack.h" int main () {cout<<endl;//Flushes the buffer stack SS while wrapping;  Defines the object int x=0;  Char ch;  cout<< "<I>-----push data to stack!\n";  cout<< "<O>-----pop data from stack!\n";  cout<< "<S>-----Show content of stack!\n"; cout<< "<Q>-----Quit!!!!!!!  \ n ";  while (1) {cout<< "Please select a item:"; Cin>>ch;ch=toupper (ch); switch (CH) {case ' I ': cout<< "Enter The value of the want to push: "; Cin>>x;ss.push (ch); Break;case ' O ': X=ss.pop ();cout<<" Pop "<<x< < "from stack!\n"; Break;case ' S ': ss.    Showstack (); break;    Case ' Q ': return 0;break; default:cout<< "You have iputted a wrong item!!!! Please try AgAin!\n ";    Continue;} }}


C + + simple implementation of pressure stack out of stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.