-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaula29.java
62 lines (54 loc) · 1.32 KB
/
aula29.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*import java.util.*;
class aula29
{
static Queue<Integer> q = new LinkedList<Integer>();
static boolean checkSorted(int n)
{
Stack<Integer> st = new Stack<Integer>();
int expected = 1;
int fnt;
while(q.size() != 0)
{
fnt = q.peek();
q.poll();
if(fnt == expected)
expected++;
else
{
if(st.size() == 0)
{
st.push(fnt);
}
else if(st.size() != 0 && st.peek() < fnt)
{
return false;
}
else
st.push(fnt);
}
while(st.size() != 0 && st.peek() == expected)
{
st.pop();
expected++;
}
}
if(expected -1 == n && st.size() == 0)
return true;
return false;
}
public static void main(String[] args)
{
q.add(5);
q.add(1);
q.add(2);
q.add(3);
q.add(4);
int n = q.size();
if(checkSorted(n))
System.out.println("yes");
else
System.out.println("No");
}
}
*/
//https://www.geeksforgeeks.org/check-queue-can-sorted-another-queue-using-stack/?ref=lbp