Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand the stack of java data structure

Shulou Source: shulou.com Published: 2022-06-02 02:56:40 10月14日 Update

In this issue, the editor will bring you a stack on how to understand the java data structure. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The stack is a first-in-first-out data structure, just like a bullet clip. When I heard about the stack, I thought the stack was the bottom of the java. It turns out later that it's not, it's just a concept, and you can realize it in any way you can think of. The bottom layer of the stack is implemented in an array, and the following example roughly simulates the implementation of java. The underlying layer of the arraylist collection is also implemented in arrays.

Public class MyStack {

Int [] elements

Public MyStack () {

Elements = new int [0]

}

/ / to add an element is to add an element to an array, focusing on the value

Public void push (int ele) {

/ / add 1 to the length of the array, and you can expand the capacity by multiple. It seems that the capacity in java is expanded by 1.

Int [] newArr = new int [elements.length+1]

/ / copy the elements from the original array to the new array

For (int iTuno Bandi)

Tags: Arrays elements data data structures structures advanced that is underlying content mode concept analysis maximum subscript professional small and medium examples multiples rich content just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Apple Shulou Tech Info macOS OPPO Reno