课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Standard queue operations in Java
- [Instructor] To use queues in Java, we have the java.util.Queue interface. We'll import it at the top. Since an interface is not concrete, we'll need to instantiate an implementation of the interface in order to use it. In Java, we can choose between a LinkedList and a priority queue. LinkedList is a pretty standard queue implementation, so we're going to use it for our implementation of the queue interface. To create a queue, we'll create a new queue object from a LinkedList. It will contain integers. Like LinkedList, the queue interface is generic so it can contain elements of any type you specify. To add elements to the queue, we'll use the add method. We'll add two, three and a few other numbers. Now, to follow the FIFO policy, the first item in the queue must be the first item out of the queue. This means the number two will be removed first since it was added first. To remove this number, we can use the remove method. Let's save it in a variable called removedItem and we'll…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-
-