专注Java教育14年 全国咨询/投诉热线:444-1124-454
赢咖4LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 堆栈结构详解

堆栈结构详解

更新时间:2021-08-23 11:41:26 来源:赢咖4 浏览1320次

堆栈是具有有限(预定义)容量的抽象数据类型。 它是一个简单的数据结构,允许按特定顺序添加和删除元素。 每次添加元素时,它都会位于堆栈的顶部 ,唯一可以删除的元素是位于堆栈顶部的元素,就像一堆对象一样。

堆栈的基本功能 (Basic features of Stack)

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.

堆栈被认为是溢出状态,当它完全充满,被认为是下溢状态,如果它完全是空的。

堆栈的应用 (Applications of Stack)

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)

表达式转换(后缀为前缀,后缀为前缀等)

堆栈数据结构的实现 (Implementation of Stack Data Structure)

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。

堆栈操作分析 (Analysis of Stack Operations)

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)因为我们总是必须从堆栈顶部插入或删除数据,这是一个一步的过程。

以上就是赢咖4小编介绍的"堆栈结构详解",希望对大家有帮助,想了解更多可查看Java堆栈。赢咖4在线学习教程,针对没有任何Java基础的读者学习,让你从入门到精通,主要介绍了一些Java基础的核心知识,让同学们更好更方便的学习和了解Java编程,感兴趣的同学可以关注一下。

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>