-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_question.java
More file actions
47 lines (38 loc) · 1 KB
/
stack_question.java
File metadata and controls
47 lines (38 loc) · 1 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
import java.util.*;
public class stack_question {
public static void pushAtBottom(Stack<Integer> s,int data){
if(s.isEmpty()){
s.push(data);
return;
}
int t=s.pop();
pushAtBottom(s, data);
s.push(t);
}
public static String revString(String s){
Stack<Character> p=new Stack<>();
int i=0;
while(i<s.length()){
p.push(s.charAt(i));
i++;
}
StringBuilder a=new StringBuilder();
while(!p.isEmpty()){
a.append(p.pop());
}
String l=a.toString();
return l;
}
public static void main(String args[]){
Stack<Integer> s=new Stack<>();
s.push(1);
s.push(2);
s.push(3);
String n = revString("shivakant shukla bainti kala");
//pushAtBottom(s,4);
// while(!s.isEmpty()){
// System.out.println(s.pop());
// }
System.out.println(" "+n);
}
}