-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackArray.java
More file actions
72 lines (68 loc) · 1.11 KB
/
Copy pathstackArray.java
File metadata and controls
72 lines (68 loc) · 1.11 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
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*;
class stackArray{
static int max=10;
static int top=-1;
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
int arr[]=new int[max];
boolean v=true;
while(v){
System.out.println("enter the function to perform");
int z=s.nextInt();
switch(z)
{
case 1:{
int a=s.nextInt();
push(arr,a);
break;
}
case 2:{
pop(arr);
break;
}
case 3:{
System.out.println(peek(arr));
break;
}
default:{
System.out.println("GOOD BYE");
v=false;
break;
}
}
}
}
static void push(int arr[],int a){
if(top<(max-1)){
top++;
arr[top]=a;
}
else{
if(overflow()){
System.out.println("cant put element in array");
}
}
}
static void pop(int arr[]){
if(top>-1){
System.out.println(arr[top]);
arr[top]=0;
top--;
for(int i=0;i<=top;i++){
System.out.println(arr[i]);
}
}
else{
System.out.println("cant pop element in array");
}
}
static int peek(int arr[]){
return arr[top];
}
static boolean overflow(){
return true;
}
static boolean underflow(){
return true;
}
}