萌新刷力扣——栈与递归篇

java常用作栈结构的类:

oracle官网文档:

下列是java常用作栈结构的类与接口

ArrayDeque (Java Platform SE 8 ) (oracle.com) 

Queue (Java Platform SE 8 ) (oracle.com)

Deque (Java Platform SE 8 ) (oracle.com)

LinkedList (Java Platform SE 8 ) (oracle.com)

Stack (Java Platform SE 8 ) (oracle.com)

相关方法介绍:

(15条消息) java集合超详解_phial03的博客-优快云博客_java集合

(15条消息) JAVA队列( Queue ) 详解_java叶新东老师的博客-优快云博客_java queue

Interface Queue<E>

Modifier and TypeMethod and Description
booleanadd(E e)
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning upon success and throwing an if no space is currently available.trueIllegalStateException
Eelement()
Retrieves, but does not remove, the head of this queue.
booleanoffer(E e)
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
Epeek()
Retrieves, but does not remove, the head of this queue, or returns if this queue is empty.null
Epoll()
Retrieves and removes the head of this queue, or returns if this queue is empty.null
Eremove()
Retrieves and removes the head of this queue.

Interface Deque<E>

Modifier and TypeMethod and Description
booleanadd(E e)

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

voidaddFirst(E e)

Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

voidaddLast(E e)

Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions, throwing an IllegalStateException if no space is currently available.

booleancontains(Object o)

Returns true if this deque contains the specified element.

EgetFirst()

Retrieves, but does not remove, the first element of this deque.

EgetLast()

Retrieves, but does not remove, the last element of this deque.

Epeek()

Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

EpeekFirst()

Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty.

EpeekLast()

Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty.

Epoll()

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns null if this deque is empty.

EpollFirst()

Retrieves and removes the first element of this deque, or returns null if this deque is empty.

EpollLast()

Retrieves and removes the last element of this deque, or returns null if this deque is empty.

Eremove()

Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque).

Class LinkedList<E>

Modifier and TypeMethod and Description
booleanadd(E e)

Appends the specified element to the end of this list.

voidadd(int index, E element)

Inserts the specified element at the specified position in this list.

booleanaddAll(Collection<? extends E> c)

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.

booleanaddAll(int index, Collection<? extends E> c)

Inserts all of the elements in the specified collection into this list, starting at the specified position.

voidaddFirst(E e)

Inserts the specified element at the beginning of this list.

voidaddLast(E e)

Appends the specified element to the end of this list.

voidclear()

Removes all of the elements from this list.

Eget(int index)

Returns the element at the specified position in this list.

EgetFirst()

Returns the first element in this list.

EgetLast()

Returns the last element in this list.

Epeek()

Retrieves, but does not remove, the head (first element) of this list.

EpeekFirst()

Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.

EpeekLast()

Retrieves, but does not remove, the last element of this list, or returns null if this list is empty.

Epoll()

Retrieves and removes the head (first element) of this list.

EpollFirst()

Retrieves and removes the first element of this list, or returns null if this list is empty.

EpollLast()

Retrieves and removes the last element of this list, or returns null if this list is empty.

Epop()

Pops an element from the stack represented by this list.

voidpush(E e)

Pushes an element onto the stack represented by this list.

Eremove()

Retrieves and removes the head (first element) of this list.

上述所列方法只提供了集中比较常用的方法,详细方法请前往oracle进行查看。

栈与递归leetcode算法题:

栈与计算器

逆波兰表达式介绍:

逆波兰表达式是一种后缀表达式,所谓后缀就是指算符写在后面。

逆波兰表达式计算求值:

如果遇到操作数,则将操作数入栈;

如果遇到运算符,则将两个操作数出栈,其中先出栈的是右操作数,后出栈的是左操作数,使用运算符对两个操作数进行运算,将运算得到的新操作数入栈。

整个逆波兰表达式遍历完毕之后,栈内只有一个元素,该元素即为逆波兰表达式的值。

递归与分治

将整个问题分解成若干小问题后再分而治之。如果分解得到的子问题相对来说还是太大,则可反复使用分治策略将这些子问题分成更小的同类型子问题,直至产生方便求解的子问题,必要时逐步合并这些子问题的解,从而得到问题的解。
分治算法可以由递归过程来表示,因为分治法就是一种找大规模问题与小规模问题关系的方法,是递归设计的一种具体策略。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ikkkp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值