Implementation of the "chain stack" code [Iot 1132-11]

Source: Internet
Author: User
# Include <iostream. h> template <class T> struct Stu {t data; Stu <t> * Next ;}; template <class T> class linkstack {public: linkstack () {Top = NULL ;}~ Linkstack (); void push (t x); t POP (); t gettop () {If (top! = NULL) return top-> data ;}; int empty () {Top = NULL? Return 1: Return 0 ;}; PRIVATE: Stu <t> * Top ;}; template <class T> class linkstack <t >:: push (t x) {S = new Stu; s-> DATA = x; s-> next = top; Top = s;} template <class T> class linkstack <t>: Pop () {Stu <t> * P; t x; If (Top = NULL) throw "wrong"; X = Top-> data; P = top; Top = Top-> next; delete P; return X;} int main () {linkstack <int> S1; int m; do {cout <"-----------------------" <Endl; cout <"input 1 starts to stack" <Endl; cout <"input 2 starts to stack" <Endl; cout <"input 3 starts to read the top of the stack" <Endl; cout <"input 4 starts to judge whether it is null" <Endl; CIN> m; Switch (m) {Case 1: cout <"Enter the element value of the stack" <Endl; CIN> A; s1.push (a); break; Case 2: cout <"this operation is an outbound stack" <Endl; s1.pop (); break; Case 3: int V; cout <"this operation is the top of the read stack" <Endl; s1.gettop (); break; Case 4: cout <"this operation is to judge that the stack is empty" <Endl; s1.empty (); break;} while (1); Return 0 ;}

Implementation of the "chain stack" code [Iot 1132-11]

Related Article

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.