How to print the reverse of the String java is object orientated language
without using any predefined function like reverse()
?
public class MyStack {
private int maxSize;
private char[] stackArray;
private int top;
public MyStack(int s) {
maxSize = s;
stackArray = new char[maxSize];
top = -1;
}
public void push(char j) {
stackArray[++top] = j;
}
public char pop() {
return stackArray[top--];
}
public char peek() {
return stackArray[top];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public static void main(String[] args) {
MyStack theStack = new MyStack(10);
String s="abcd";
for(int i=0;i