堆栈应该由数组还是链表 java 组成? [英] Should stacks be made from arrays or linked list java?

查看:42
本文介绍了堆栈应该由数组还是链表 java 组成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为类编写一个堆栈,虽然我了解堆栈如何工作的概念,但我没有被告知它们是使用数组还是链表或其他东西制作的?大多数堆栈是如何创建的?

I have to write a stack for class and while I understand the concept of how a stack works, I wasn't told if they are made using an array or a linked list or something else? How are most stacks created?

推荐答案

ArrayDeque 是堆栈概念的可靠类实现.这个类以最有效的方式实现了堆栈.各种方法的细节请看类实现.

ArrayDeque is a solid class implementation of the stack concept. This class has implemented stack in the most efficient way. Please look at the class implementation for the details of various methods.

http://www.docjar.com/html/api/java/util/ArrayDeque.java.html

更具体地说,看看 public E pollFirst(){...}public void addFirst(E e)

More specifically, look at public E pollFirst(){...} and public void addFirst(E e)

这篇关于堆栈应该由数组还是链表 java 组成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆