-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserHistoryUpgrade.java
37 lines (35 loc) · 1.26 KB
/
BrowserHistoryUpgrade.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package StacksAndQueues_Lab;
import java.util.ArrayDeque;
import java.util.Scanner;
public class BrowserHistoryUpgrade {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
ArrayDeque <String> URLs = new ArrayDeque<>();
ArrayDeque <String> forward = new ArrayDeque<>();
while (!input.equals("Home")){
if(input.equals("back")){
if(URLs.size()<=1){
System.out.println("no previous URLs");
}else{
String lastURL = URLs.pop();
forward.push(lastURL);
System.out.println(URLs.peek());
}
}else if(input.equals("forward")){
if(forward.isEmpty()){
System.out.println("no next URLs");
}else{
String nextURL = forward.pop();
URLs.push(nextURL);
System.out.println(URLs.peek());
}
}else{
URLs.push(input);
System.out.println(URLs.peek());
forward.clear();
}
input = scan.nextLine();
}
}
}