package com.lee.stack;
public class stackInitial<T>{
public char[] arr;
public int maxsize;
public int top;
public stackInitial(int max) {
arr = new char[max];
top = -1;
}
public void push(char number) {
arr[++top] = number;
}
public char pop() {
return arr[top--];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxsize - 1);
}
public static void main(String[] args) {
stackInitial a_stack = new stackInitial(10);
a_stack.push('1');
a_stack.push('0');
a_stack.push('3');
a_stack.push('3');
a_stack.push('a');
a_stack.push('n');
while(!a_stack.isEmpty())
{
System.out.println(a_stack.pop());
}
}
}
package com.lee.stack;
public class reverseWord {
public String input;
public String reverse="";
public reverseWord(String input)
{
this.input = input;
}
public String Reverse()
{
stackInitial a = new stackInitial(input.length());
for(int i=0;i<input.length();i++)
{
a.push(input.charAt(i));
}
while(!a.isEmpty())
{
//System.out.println(a.pop());
reverse+=a.pop();
}
return reverse;
}
public int count()
{
return (input.length());
}
public static void main(String[] args) {
reverseWord a = new reverseWord("But you are a girl");
System.out.println(a.Reverse());
}
}