stack reverse in java code example
Example: how to reverse the stack in java
public void rev() {
ArrayStack s1 = new ArrayStack();
int[] data2;
data2 = new int[1000];
for (int i = 0 ; i<size();i++) {
data2[i] = data[i];
}
for (int i = 0 ; i<size();i++) {
s1.push(data2[i]);
}
for (int i = 0 ; i<size();i++) {
data2[i] = s1.pop();
System.out.print(data2[i] + " ");
}
System.out.println();
}