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