Java implementation stacks and queues

Source: Internet
Author: User

1 classNode {2     intVal;3 Node Next;4     5Node (intx) {6val =x;7Next =NULL;8     }9 }Ten  One classStack { A Node top; -      -      PublicNode Peek () { the         if(Top! =NULL) { -             returntop; -         } -         return NULL; +     } -      +      PublicNode Pop () { A         if(top = =NULL) { at             return NULL; -}Else { -Node temp =NewNode (top.val); -top =Top.next; -             returntemp; -         } in     } -      Public voidpush (Node N) { to         if(n! =NULL) { +N.next =top; -top =N; the         } *     } $ }Panax Notoginseng  - classQueue { the Node First, last; +      A      Public voidEnqueue (Node N) { the         if(First = =NULL) { +First =N; -Last =First ; $}Else { $Last.next =N; -Last =N; -         } the     } -     Wuyi      PublicNode dequeue () { the         if(First = =NULL) { -             return NULL; Wu}Else { -Node temp =NewNode (first.val); AboutFirst =First.next; $             returntemp; -         } -     }  -}

Java implementation stacks and queues

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.