更新時間:2021-08-23 11:41:26 來源:動力節點 瀏覽1759次
堆棧是具有有限(預定義)容量的抽象數據類型。 它是一個簡單的數據結構,允許按特定順序添加和刪除元素。 每次添加元素時,它都會位于堆棧的頂部 ,唯一可以刪除的元素是位于堆棧頂部的元素,就像一堆對象一樣。
Stack is an ordered list of similar data type.
堆棧是類似數據類型的有序列表 。
Stack is a LIFO(Last in First out) structure or we can say FILO(First in Last out).
Stack是LIFO ( 后進先出)結構,或者我們可以說FILO ( 后進先出)。
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()函數用于將新元素插入到堆棧中,而pop()函數用于從堆棧中刪除元素。 插入和移除都只能在Stack的稱為Top的一端進行。
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.
堆棧被認為是溢出狀態,當它完全充滿,被認為是下溢狀態,如果它完全是空的。
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.
堆棧最簡單的應用是反轉一個單詞。 您將給定的單詞按字母順序推入堆棧,然后從堆棧中彈出字母。
There are other uses also like:
還有其他用途,例如:
Parsing
解析中
Expression Conversion(Infix to Postfix, Postfix to Prefix etc)
表達式轉換(后綴為前綴,后綴為前綴等)
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.
使用數組或鏈接列表可以輕松實現堆棧。 數組速度很快,但是大小有限,“鏈接列表”需要開銷來分配,鏈接,取消鏈接和取消分配,但大小不受限制。 在這里,我們將使用數組實現Stack。
Below mentioned are the time complexities for various operations that can be performed on the Stack data structure.
下面提到的是可以在堆棧數據結構上執行的各種操作的時間復雜度。
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()函數的時間復雜度為O(1)因為我們總是必須從堆棧頂部插入或刪除數據,這是一個一步的過程。
以上就是動力節點小編介紹的"堆棧結構詳解",希望對大家有幫助,想了解更多可查看Java堆棧。動力節點在線學習教程,針對沒有任何Java基礎的讀者學習,讓你從入門到精通,主要介紹了一些Java基礎的核心知識,讓同學們更好更方便的學習和了解Java編程,感興趣的同學可以關注一下。
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習