In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the knowledge points of the Java stack what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you read the knowledge points of this Java stack what articles will have a harvest, let's take a look at it.
1. The concept of stack
Stack (stack), also known as stack, as a data structure, is a special linear table that can only insert and delete at one end.
It is a kind of linear table with limited operation. The limitation is that insert and delete operations are only allowed at one end of the table. This end is called the top of the stack, on the contrary, the other end is called the bottom of the stack. The stack has the characteristic of first in and then out.
two。 Basic operation of stack
Build a stack: build an empty stack before using the stack
To add new elements to the stack.
Unstack: delete the top element of the stack
Read stack: query the elements at the top of the current stack
Get the size of the stack and clear the stack.
3. Methods and properties of the stack
Push is in-stack Pop is out-of-stack 4. Two implementation methods of stack: ① array (sequence table)
The array must have a fixed length (number of elements) defined in advance.
② linked list
The linked list can be seen as a small room, and each room points to the next room by pointers. The linked list is a discontinuous and non-sequential storage structure on the physical storage unit. The logical order of data elements is realized by the pointer address of the linked list. Each element contains two nodes, one is the data field (memory space) of the storage element. The other is the pointer field that points to the address of the next node. According to the direction of the pointer, linked lists can form different structures, such as single linked lists, two-way linked lists, circular linked lists, etc.
5. The difference between an array and a linked list array advantages:
1. Query elements according to the index quickly
2. It is convenient to traverse the array according to the index.
Disadvantages:
1, define a fixed length (number of elements) in advance
2, it can not adapt to the situation that the data increases or decreases dynamically.
When the data increases, it may exceed the previously defined number of elements, causing the array to cross the bounds
When data is reduced, memory is wasted.
Advantages of linked list:
1. There is no need to initialize the capacity, and you can add or subtract elements at will.
2. When adding or deleting elements, you only need to change the pointer field of the two element nodes to point to the address, so add and delete quickly.
Disadvantages:
1, because it contains a large number of pointer fields, it takes up a lot of space; looking for elements needs to traverse the linked list, which is very time-consuming.
For scenarios where you want to quickly access data and do not often insert and delete elements, select an array with a small amount of data that needs to be frequently added and deleted.
If there is no high requirement for the efficiency of accessing elements, select the linked list.
6. The function of stack is 6.1. Save local variables:
It is also possible to use local variables instead of global variables all the time. Then where the local variables are stored is appropriate, that is, we can not let the function nest when there is a conflict, but also pay attention to efficiency.
6.2 Parameter transfer
The purpose of passing parameters is so that the code can be reused so that one method can be applied to more situations without the need to write N sets of similar code for N cases. Then what method is used to pass the parameters? You can choose from:
6.3 Save the value of the register
If there is a conflict in the parameters of the register, the value of the register can be temporarily pressed into the stack.
6.4 other functions
1) Stack is the basis of each function architecture, which realizes the reuse of functions.
2) when a problem occurs, you can use the stack to understand the situation of the problem.
3) Stack is the basis of constructing multitasking mode of operating system.
This is the end of the article on "what are the knowledge points of the Java stack?" Thank you for reading! I believe you all have a certain understanding of "what are the knowledge points of the Java stack". If you want to learn more knowledge, you are welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.