课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Basic stack operations in Java

Basic stack operations in Java - Java教程

课程: Java Algorithms

Basic stack operations in Java

- [Instructor] Java has a built-in stack data structure that we can use in our custom algorithms. It lives in the java.util package. We can create a stack using the constructor. Like the other data structures, it's generic and this stack will hold strings. To add items to the stack, we'll use the push method. We'll also use function names to roughly emulate the run time stack. The run time stack uses objects with lots of information in them, but we'll just be pushing on strings. It all starts with the main method, then let's say a builder function is used, an external service might be called and once we get the response back, the execution for external service will be finished. So we'll pop that off the stack, then maybe we parse the response. That's another function call. Once that's finished, we'll pop it off. This will also conclude the builder's execution, so we'll pop off the builder and then finally the main method. With the stack, we can keep track of where each function was…

内容