-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecStack.java
More file actions
60 lines (52 loc) · 1.32 KB
/
SpecStack.java
File metadata and controls
60 lines (52 loc) · 1.32 KB
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
import java.util.Scanner;
import java.util.Stack;
class SpeStack{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
Stack<Integer> s=new Stack<>();
GfG g=new GfG();
while(!g.isFull(s,n)){
g.push(sc.nextInt(),s);
}
System.out.println(g.min(s));
}
}
}
/*This is a function problem.You only need to complete the function given below*/
/*Complete the function(s) below*/
class GfG{
static Stack<Integer> minStack=new Stack<>();
public void push(int a,Stack<Integer> s)
{
//add code here.
if(isEmpty(s) || minStack.peek()>=a)
minStack.add(a);
s.add(a);
}
public int pop(Stack<Integer> s)
{
//add code here..
int val = s.pop();
if (val == minStack.peek())
minStack.pop();
return val;
}
public int min(Stack<Integer> s)
{
//add code here.
return minStack.peek();
}
public boolean isFull(Stack<Integer>s, int n)
{
//add code here.
return s.size()>n;
}
public boolean isEmpty(Stack<Integer>s)
{
//add code here.
return s.isEmpty();
}
}