Go Stack Simple implementation

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT") type Stack struct {top intdata [10]int}func initstack (S *stack) {s.top = 0}func push (s *stack,  element int) {S.data[s.top] = Elements.top++}func Pop (s *stack) int {S.top--return S.data[s.top]}func showstack (S *Stack) {for I: = s.top; I >= 0; i--{fmt. Printf ("element%d is%d \ t", I, S.data[i])}}func showdiscribe () {fmt. Println ("***********operations description****************") fmt. Println ("") fmt. Println ("Press 1 push element to Stack") fmt. Println ("Press 2 pop element to Stack") fmt. Println ("Press 3 show elements to Stack") fmt. Println ("Press 4 show Operations") FMT. Println ("Press 5 exit") Fmt. Println ("") fmt. Println ("*************************************************")}func Main () {Showdiscribe () var op intvar value INTs: = New (Stack) Initstack (s) for {fmt. SCANF ("%d", &op) switch op {case 1:fmt. PRINTLN ("Please input the Vaule") fmt. SCANF ("%d", &value) push (s, value) case 2:fmt. Println ("The value is:", POPs (s)) case 3:fmt. Println ("All elements:") Showstack (s) CAse 4:showdiscribe () Case 5:goto Exit}}exit:} 

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.