更新時間:2021-08-23 11:41:26 來源:動力節(jié)點 瀏覽1870次
堆棧是具有有限(預(yù)定義)容量的抽象數(shù)據(jù)類型。 它是一個簡單的數(shù)據(jù)結(jié)構(gòu),允許按特定順序添加和刪除元素。 每次添加元素時,它都會位于堆棧的頂部 ,唯一可以刪除的元素是位于堆棧頂部的元素,就像一堆對象一樣。
Stack is an ordered list of similar data type.
堆棧是類似數(shù)據(jù)類型的有序列表 。
Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
Stack是LIFO ( 后進(jìn)先出)結(jié)構(gòu),或者我們可以說FILO ( 后進(jìn)先出)。
push() function is used to insert new elements into the Stack and pop() function is used to remove an element from the stack. Both insertion and removal are allowed at only one end of Stack called Top.
push()函數(shù)用于將新元素插入到堆棧中,而pop()函數(shù)用于從堆棧中刪除元素。 插入和移除都只能在Stack的稱為Top的一端進(jìn)行。
Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state if it is completely empty.
堆棧被認(rèn)為是溢出狀態(tài),當(dāng)它完全充滿,被認(rèn)為是下溢狀態(tài),如果它完全是空的。
The simplest application of a stack is to reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack.
堆棧最簡單的應(yīng)用是反轉(zhuǎn)一個單詞。 您將給定的單詞按字母順序推入堆棧,然后從堆棧中彈出字母。
There are other uses also like:
還有其他用途,例如:
Parsing
解析中
Expression Conversion(Infix to Postfix, Postfix to Prefix etc)
表達(dá)式轉(zhuǎn)換(后綴為前綴,后綴為前綴等)
Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are limited in size and Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in size. Here we will implement Stack using array.
使用數(shù)組或鏈接列表可以輕松實現(xiàn)堆棧。 數(shù)組速度很快,但是大小有限,“鏈接列表”需要開銷來分配,鏈接,取消鏈接和取消分配,但大小不受限制。 在這里,我們將使用數(shù)組實現(xiàn)Stack。
Below mentioned are the time complexities for various operations that can be performed on the Stack data structure.
下面提到的是可以在堆棧數(shù)據(jù)結(jié)構(gòu)上執(zhí)行的各種操作的時間復(fù)雜度。
Push Operation : O(1)
推入操作 :O(1)
Pop Operation : O(1)
彈出操作 :O(1)
Top Operation : O(1)
最高操作 :O(1)
Search Operation : O(n)
搜索操作 :O(n)
The time complexities for push() and pop() functions are O(1) because we always have to insert or remove the data from the top of the stack, which is a one step process.
push()和pop()函數(shù)的時間復(fù)雜度為O(1)因為我們總是必須從堆棧頂部插入或刪除數(shù)據(jù),這是一個一步的過程。
以上就是動力節(jié)點小編介紹的"堆棧結(jié)構(gòu)詳解",希望對大家有幫助,想了解更多可查看Java堆棧。動力節(jié)點在線學(xué)習(xí)教程,針對沒有任何Java基礎(chǔ)的讀者學(xué)習(xí),讓你從入門到精通,主要介紹了一些Java基礎(chǔ)的核心知識,讓同學(xué)們更好更方便的學(xué)習(xí)和了解Java編程,感興趣的同學(xué)可以關(guān)注一下。
初級 202925
初級 203221
初級 202629
初級 203743