-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
42 lines (32 loc) · 904 Bytes
/
App.java
File metadata and controls
42 lines (32 loc) · 904 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
package ds.Stack;
public class App {
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack theStack = new Stack(20);
// theStack.push(23);
// theStack.push(33);
// theStack.push(13);
// theStack.push(25);
// theStack.push(25);
// theStack.push(25);
while(!theStack.isEmpty()){
long value= theStack.pop();
System.out.println(value);
}
System.out.println(reverseString("HELLO TILL"));
}
public static String reverseString(String str){
int stackSize = str.length(); // get the max size
Stack theStack = new Stack(stackSize); // we make the stack
for(int j = 0; j< str.length(); j++){
char ch = str.charAt(j); // getting a char from the input String
theStack.push(ch);
}
String result = "";
while(!theStack.isEmpty()){
long ch = theStack.pop();
result = result+ ch;// appending the output
}
return result;
}
}