This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT" "OS") type Node struct {val intpnode *node}type Stack struct {ptop,pbottom *node}func initstack (PS Tack *stack) {pnew:=new (Node) pnew.pnode=nilpstack.ptop=pnewpstack.pbottom=pnewif Pstack.ptop==nil | | pStack.pBottom ==nil {fmt. Println ("Allocate head node memory failed, program exits") OS. Exit ( -1)}}func push (pstack *stack,val int) {pnew:=new (Node) pnew.val=valif Pnew==nil {fmt. Println ("Allocate head node memory failed, program exits") OS. Exit ( -1)}pnew.pnode=pstack.ptoppstack.ptop=pnew}func pop (pstack *stack) (bool, int) {if IsEmpty (Pstack) {return false, 0}reval:=pstack.ptop.valpstack.ptop=pstack.ptop.pnodereturn True,reval}func IsEmpty (pstack *Stack) bool {if Pstack.ptop==pstack.pbottom{return True}return false}func Traverse (Pstack *stack) {if IsEmpty (pstack) {return}p:= Pstack.ptopfor;p!=pstack.pbottom;p=p.pnode {fmt. Printf ("%d", P.val)}fmt. Println ()}func Clear (Pstack *stack) {if IsEmpty (pstack) {Return}pstack.ptop=pstack.pbottom}func main () {var pstack Stackinitstack (&pstack) rebool,reval:=pop (&pstack) if Rebool {fmt. PrintF ("The stack succeeds, the stack value is:%d\n", Reval)} else {fmt. Println ("Out of stack Error")}traverse (&pstack) Clear (&pstack) traverse (&pstack)}