how to reverse the stack in java

Solutions on MaxInterview for how to reverse the stack in java by the best coders in the world

showing results for - "how to reverse the stack in java"
Zander
25 Aug 2019
1    public void rev() {
2    	ArrayStack s1 = new ArrayStack();
3    	int[] data2;
4    	data2 = new int[1000];
5    	for (int i = 0 ; i<size();i++) {
6    		data2[i] = data[i];
7    	}
8    	
9    	for (int i = 0 ; i<size();i++) {
10    	 s1.push(data2[i]);
11    	}
12    	
13    	for (int i = 0 ; i<size();i++) {
14    		data2[i] = s1.pop();
15    		System.out.print(data2[i] + " ");
16    	}
17    	System.out.println();
18    }