-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathStacks.java
More file actions
41 lines (32 loc) · 780 Bytes
/
Stacks.java
File metadata and controls
41 lines (32 loc) · 780 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
//Stack Data Strucuture implemented in Java
public class Stacks {
private int maxSize;
private long[] stackArray;
private int top;
//Class implement
public Stacks(int s){
maxSize=s;
stackArray=new long[maxSize];
top = -1;
}
//Push method
public void push(long j){
stackArray[++top] =j;
}
//pop method remove top element
public long pop(){
return stackArray[top--];
}
//return top element
public long peek(){
return stackArray[top];
}
//check if stack is empty
public boolean isEmpty(){
return (top == -1);
}
//check if stack is full
public boolean isFull(){
return (top ==maxSize-1);
}
}