Data Structure tutorial (Java description) edited by Xu xiaokai-review abstract 04

Source: Internet
Author: User

Data Structure tutorial (Java description) edited by Xu xiaokai-review abstract 04

Chapter 3 stack and queue

Stack sequential storage structure and operation implementation

Public class sequencestack implements stack {final int maxsize = 10; // assume that the initial length of the one-dimensional array of the storage stack is 10 private object [] stackarray; // define the storage Stack Array reference private int top; // define the subscript position of the top element of the stack stored in the array // operate public sequencestack () {} public sequencestack (int n) {} public void push (Object OBJ ){}...}

Stack link storage structure and operation implementation

Public class linkstack implements stack {private node top; // defines top stack pointer // operate public linkstack () {} public void push (Object OBJ ){}...}

Usually, the variable pointing to the first position of the first element is called the first pointer. The subscript position of the first element is obtained after the word is added with 1, the variable pointing to the position of the element at the end of the team is called the team-end pointer, which can directly obtain the subscript position of the element at the end of the team.

Ordered storage structure and operation implementation of queues

Public calss sequencequeue implements queue {final int maxsize = 10; // assume that the initial length of the one-dimensional array of the storage queue is 10 private object queuearray []; // define the storage queue array reference private int front, rear; // define the frontend and backend pointers public sequencequeue () {} public sequencequeue (int n) {} public void enter (Object OBJ ){}...}

Queue link storage structure and operation implementation

Public class linkqueue implements queue {private node front, rear; // define the frontend and backend pointer (reference) // operate public linkqueue () {front = rear = NULL ;}...}

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.