Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- void splitStack(Stack<Integer> st){
- Stack<Integer> tmpStack = new Stack<Integer>();
- Stack<Integer> ans = new Stack<Integer>();
- int tmp = st.pop();
- if (tmp < 0){
- ans.push(tmp);
- } else{
- tmpStack.push(tmp);
- }
- while (st.empty() == false){
- tmp = st.pop();
- if (tmp < 0){
- ans.push(tmp);
- } else{
- tmpStack.push(tmp);
- }
- }
- while (tmpStack.empty() == false){
- ans.push(tmpStack.pop());
- }
- }
- public static void main(String[] args) {
- Stack<Integer> st = new Stack<Integer>();
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- for (int i = 0; i < n; ++i){
- st.push(sc.nextInt());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement