-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStacks
More file actions
46 lines (43 loc) · 978 Bytes
/
Stacks
File metadata and controls
46 lines (43 loc) · 978 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
46
import java.util.Scanner;
public class Stack {
private int[] items;
private int top;
public Stack (int capacity) {
items=new int[capacity];
top=-1;
}
public boolean isEmpty() {
return top==-1;
}
public boolean isFull() {
return top==items.length-1;
}
public int pop() {
if(!isEmpty()) {
return items[top--];
}
return 0;
}
public void push(int sayi) {
top++;
items[top]=sayi;
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("Kapasite");
int capacity=scanner.nextInt();
Stack stack=new Stack(capacity);
stack.push(10);
stack.push(15);
stack.push(25);
stack.push(35);
System.out.println("silinen : "+ stack.pop());
stack.push(10);
stack.push(15);
stack.push(55);
System.out.println("silinen : "+ stack.pop());
System.out.println("silinen : "+ stack.pop());
System.out.println("silinen : "+ stack.pop());
System.out.println("silinen : "+ stack.pop());
}
}