Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Scanner;
- public class L08_BrowserHistoryExtend {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayDeque<String> stack = new ArrayDeque<>();
- ArrayDeque<String> queue = new ArrayDeque<>();
- String input;
- while (!"Home".equals(input = scanner.nextLine())) {
- String currentInput = "";
- if ("back".equals(input)) {
- if (stack.size() <= 1) {
- System.out.println("no previous URLs");
- continue;
- } else {
- queue.offer(stack.pop());
- currentInput = stack.peek();
- }
- } else if ("forward".equals(input)) {
- if (queue.size() < 1) {
- System.out.println("no next URLs");
- continue;
- }else {
- currentInput = queue.peek();
- queue.poll();
- }
- } else {
- currentInput = input;
- stack.push(input);
- }
- System.out.println(currentInput);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement