Java data structure and algorithm------stack

Source: Internet
Author: User

1  PackageiYou.neugle.list;2 3  Public classMyseqstack<t> {4     PrivateStack stack =NewStack ();5 6     classStack {7          Public intMaxSize = 10;8          Publict[] data = (t[])NewObject[maxsize];9          Public inttop =-1;//stack Top pointerTen     } One  A     //Initialize Stack -      Public voidSeqstackinit () { -          This. Stack.top = 1; theSYSTEM.OUT.PRINTLN ("Stack initialization succeeded!")); -     } -  -     //into the stack +      Public voidSeqstackpush (T data) { -         if( This. Stack.top = = This. stack.maxsize-1) { +System.out.println ("The contents of the stack are full!")); A             return; at         } -          This. stack.data[++ This. stack.top] =data; -     } -  -     //out of the stack -      PublicT Seqstackpop () { in         if( This. Stack.top = =-1) { -System.out.println ("The contents of the stack are empty!")); to         } +T data = This. Stack.data[stack.top]; -          This. stack.data[ This. stack.top] =NULL; the          This. stack.top--; *         returndata; $     }Panax Notoginseng  -     //get top of stack element the      PublicT Seqstackpeek () { +         if( This. Stack.top = =-1) { ASystem.out.println ("The contents of the stack are empty!")); the             return NULL; +         } -         return  This. stack.data[ This. Stack.top]; $     } $}

Java data structure and algorithm------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.