- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackFromArray.java
More file actions
Latest commit
41 lines (31 loc) · 880 Bytes
/
Copy pathStackFromArray.java
File metadata and controls
41 lines (31 loc) · 880 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
packagecracking.coding;
publicclassStackFromArray {
staticintstackSize=100;
staticint [] buffer = newint[(stackSize*3)];
staticint [] stackPointer = {-1,-1,-1};
publicintpop(intstackNumber){
if(stackPointer[(stackNumber)] == -1){
System.out.println("Empty stack");
}else{
intdata = buffer[absTopOfStack(stackNumber)];
buffer[absTopOfStack(stackNumber)]=0;
stackPointer[stackNumber]--;
returndata;
}
return0;
}
publicvoidpush(intdata, intstackNumber){
if(stackPointer[stackNumber]+1 >= stackSize){
System.out.println("Stack full");
}else{
stackPointer[stackNumber]++;
buffer[absTopOfStack(stackNumber)+1] = data;
}
}
publicstaticintabsTopOfStack(intstackNumber){
returnstackNumber*stackSize*stackPointer[stackNumber];
}
publicvoidprint(intstackNumber){
System.out.println();
}
}