-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStackImp.java
More file actions
45 lines (37 loc) · 1004 Bytes
/
StackImp.java
File metadata and controls
45 lines (37 loc) · 1004 Bytes
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
import java.io.*;
import java.util.*;
class StackImp{
static void stack_push(Stack<Integer> stack){
for(int i = 0; i < 5; i++){
stack.push(i);
}
}
static void stack_pop(Stack<Integer> stack){
System.out.println("Pop: ");
for(int i = 0; i< 5; i++){
Integer y = (Integer) stack.pop();
System.out.println(y);
}
}
static void stack_peek(Stack<Integer> stack){
Integer element = (Integer) stack.peek();
System.out.println("Stack top: "+ element);
}
static void stack_search(Stack<Integer> stack, int element){
Integer pos = (Integer) stack.search(element);
if(pos == 1){
System.out.println("Element not in stack.");
}else{
System.out.println("Element found at: "+ pos);
}
}
public static void main(String[] args){
Stack<Integer> stack = new Stack<Integer>();
stack_push(stack);
stack_pop(stack);
stack_peek(stack);
stack_search(stack);
stack_search(stack, 5);
stack_search(stack,3);
}
}