forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqe.java
More file actions
61 lines (61 loc) · 920 Bytes
/
qe.java
File metadata and controls
61 lines (61 loc) · 920 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.util.*;
import java.lang.*;
import java.io.*;
class rev
{
public int arr[];
public int top;
public int size;
static int x;
public rev(int n){
size=n;
arr =new int[size];
top=-1;
}
void push(int j){
if(top<size-1){
top++;
arr[top]=j;
}}
void pop(){
if(top>=0){
x=arr[top];
top--;
}}
public static void main (String[] args) throws IOException
{
int s1,i,tempu;
Scanner sc = new Scanner(System.in);
System.out.println("ENTER SIZE OF STACK");
s1=sc.nextInt();
rev sta= new rev(s1);
rev sta1 = new rev(s1);
System.out.println("ENTER NUMBERS TO BE PUSHED");
for(i=0;i<s1;i++){
System.out.println("ENTER");
tempu=sc.nextInt();
sta.push(tempu);
}
int temp,t1,k,count=1;
for(i=0;i<s1;i++)
{
sta.pop();
temp=x;
for(k=0;k<(s1-count);k++){
sta.pop();
t1=x;
sta1.push(t1);
}
sta.push(temp);
for(k=0;k<(s1-count);k++){
sta1.pop();
t1=x;
sta.push(t1);
}
count++;
}
for(i=0;i<s1;i++)
{
sta.pop();
System.out.println(x);
}}}