Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Scanner;
  3.  
  4. public class L08_BrowserHistoryExtend {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. ArrayDeque<String> stack = new ArrayDeque<>();
  8. ArrayDeque<String> queue = new ArrayDeque<>();
  9.  
  10.  
  11. String input;
  12. while (!"Home".equals(input = scanner.nextLine())) {
  13. String currentInput = "";
  14. if ("back".equals(input)) {
  15. if (stack.size() <= 1) {
  16. System.out.println("no previous URLs");
  17. continue;
  18. } else {
  19. queue.offer(stack.pop());
  20. currentInput = stack.peek();
  21. }
  22. } else if ("forward".equals(input)) {
  23. if (queue.size() < 1) {
  24. System.out.println("no next URLs");
  25. continue;
  26. }else {
  27.  
  28. currentInput = queue.peek();
  29. queue.poll();
  30. }
  31. } else {
  32. currentInput = input;
  33. stack.push(input);
  34.  
  35. }
  36. System.out.println(currentInput);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement