课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Stack algorithms: Next greater element
- [Instructor] Let's translate the next greater element algorithm into Java code. The first step is to create a function. Then we'll check our base case. If the array is empty, we'll print out an empty line and return. If the array has items, we'll initialize our stack and push the first element of the array onto the stack. In this algorithm, we're going to iterate through the array, trying to find the next greater element for each item. In each iteration, we're checking whether the current item in the array is the next greater element for the item at the top of the stack. If it is, we'll display it to the console but no matter what, we'll want to push this next element onto the stack. If it is, we'll display it to the console but no matter what, we'll want to push the next element onto the stack so we can find its next greater element. To check if the next variable is the next greater element for the item on top of the stack, we need to make sure the stack is not empty. If it does…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
(已锁定)
What is a queue?1 分钟 53 秒
-
(已锁定)
Standard queue operations in Java3 分钟 38 秒
-
(已锁定)
Queue algorithms: Generate binary numbers4 分钟 41 秒
-
(已锁定)
What is a stack?1 分钟 58 秒
-
(已锁定)
Basic stack operations in Java3 分钟 32 秒
-
(已锁定)
Stack algorithms: Theorizing an algorithm5 分钟 21 秒
-
(已锁定)
Stack algorithms: Next greater element3 分钟 57 秒
-
(已锁定)
Stack algorithms: Matching parentheses4 分钟 49 秒
-
(已锁定)
Solution: Evaluate reverse polish notation4 分钟 16 秒
-
(已锁定)
-
-
-