Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the common data structure LinkedList Set collection

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares to you is about what the common data structure LinkedList Set collection is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Four common data structures:

1. Stack structure:

The first-in-first-out feature. (just like a magazine, the one who goes in first and the one who goes in later is low.)

two。 Queue structure:

First-in, first-out. (just like the security check, first in, first out.)

3. Array structure:

Finding elements is fast, but adding and deleting elements is slow.

4. Linked list structure:

Adding and deleting elements is fast, but finding elements is slow.

LinkedList: (a subclass under the List API, which is at the same level as ArrayList)

1. The bottom layer is the linked list structure.

two。 Some of its unique methods:

AddFirst (Ee): add an element to the beginning of the collection

AddLast (Ee): adds an element to the end of the collection

GetFirst (): get the first element in the collection

GetLast (): get the last element in the collection

RemoveFirst (): deletes the first element in the collection

RemoveLast (): deletes the last element in the collection

Pop (Ee): pops an element from the top of the collection

Push (): adds an element to the top of the collection

IsEmpty (): determines whether the collection is empty or not

3. At development time, the LinkedList collection can also be used as a stack, queue structure. At development time, the LinkedList collection can also be used as a stack, queue structure.

The method used is to call the addFirst (Ee) method and the getFirst () method

Set collection (Set is an interface and, like List, they are related at the same level)

There are only two ways to traverse the Set collection, 1. Enhance for2. Iterator

Set collection features:

Uniqueness, elements do not repeat

The subclasses of 1.Set are:

HashSet 、 LinkedHashSet

2.HashSet:

A.HashSet is unordered and the access order is different.

b. The bottom layer is the hash table structure, usually custom objects need to override HashCode methods and equals methods

C.HashSet uses the HashCode method and the equals method to keep the element unique

d. The principle of judgment is:

Judge the HashCode method first

Same:

Do not add

Different: judge equals method:

Different: add

Same: do not add

LinkedHashSet:

The 1.LinkedHashSet is ordered and the access order is the same

two。 The bottom layer is the linked list + hash table structure.

3. Keep order through linked lists. A hash table is used to ensure the uniqueness of the element.

The above is what the common data structure LinkedList Set collection is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report