Java-preliminary Understanding-Common Object API (Collection framework-linkedlist Collection-Practice stack and queue)

Source: Internet
Author: User

I. Practice

An introduction to the questions that often arise during an interview.

There are two data structures and a description of the two.

The queue is like a pipe, starting from the left side, and with the back entry, the first entry is squeezed to the right end until the right end is first extruded.

In order to meet the needs of the project, we are now ready to do the two institutions to complete our actual needs.

Some people say that using the REMOVEFISRT described in the previous section is not the way to operate, the need is to let you do a specific function of the container out, rather than write it yourself.

We should describe a container that provides the user with a container object to accomplish one of these two structures.

Two.

Now describe the queue and write a class to describe it. Queue container has a feature, can complete the first-out operation, call Play Add method, call to take the method, how to save in how to take out.

We can rely on existing containers when we make our own containers more difficult.

There are two points to note: The function of this class is not inherited, but rather by defining a particular type of object through the class, and then extracting the method of the particular type object as the method of creating the object.

Note: This method of creating a specific type of object internally, rather than inheriting a particular object, allows you to create an object that has specific functionality, without other functions, and looks more concise.

Add and Remove methods, with first and last labels, the difference is the queue, the same (AddLast and Removelast) is the stack.

Finally, determine if there are any elements in the container. It's easy to know, but is this judgment necessary?

In this case, the created class encapsulates all of the linklist's methods, and after encapsulation, we don't see linklist, only the classes we create ourselves.

In fact, this is not the right way to write, should provide a tool class.

A tool class should be provided, called a queue class, to have the defined content in the class, because this is a separate object. At the same time, Duilie () to bring public, this should be exposed to ease of use.

With a well-defined tool class, the previous example can be used in a different way.

The late 1.6 release also provides a number of new methods in the Linklist linked list structure. As shown in.

The functions of these methods and the existing methods are the same, but there are some differences, the upgrade is for a reason.

The difference needs to know which method is clearly used when developing.

GetFirst method has a feature, if there is nothing in the list, call the method, there is no thing. It throws an exception, which is called the exception without this element.

For the alternative to it, peak, returns null if there are no elements. Empty means I can make a judgment,

linklist relative ArrayList to use less, because we are mostly query action.

---restore content ends---

I. Practice

An introduction to the questions that often arise during an interview.

There are two data structures and a description of the two.

The queue is like a pipe, starting from the left side, and with the back entry, the first entry is squeezed to the right end until the right end is first extruded.

In order to meet the needs of the project, we are now ready to do the two institutions to complete our actual needs.

It has been said that using the REMOVEFISRT described in the previous section,

Java-preliminary Understanding-Common Object API (Collection framework-linkedlist Collection-Practice stack and queue)

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.