public static Stack duplicate(Stack st) { Stack ezer = new Stack(); Stack st2 = new Stack(); while (!st.isEmpty()) ezer.push(st.pop()); while (!ezer.isEmpty()) { st2.push(ezer.top()); st.push(ezer.pop()); } return st2; } public static Stack createStack() { Stack st = new Stack(); System.out.println("enter the next Value for finish enter 999"); int n =sc.nextInt(); while (n!=999) { st.push(n); System.out.println("enter the next Value for finish enter 999"); n =sc.nextInt(); } return st; } public static void toString(Stack st) { Stack s=duplicate(st); while (!s.isEmpty()) System.out.print(s.pop().toString() + " "); } public static Scanner sc=new Scanner(System.in); public static int howMany(Stack st) { int counter = 0; while(!st.isEmpty()) { st.pop(); counter ++; } return counter; } public static int returnBiggest(Stack st) { int currentBiggest = 0; currentBiggest = st.top(); while (!st.isEmpty()) { if(currentBiggest < st.top()) currentBiggest = st.top(); st.pop(); } return currentBiggest; } public static Stack dupInfo(Stack st) { Stack stCopy = duplicate(st); Stack flipped = flipStack(stCopy); Stack info = new Stack(); int current,counter; while(!flipped.isEmpty()) { current = flipped.pop(); counter = 1; while(!flipped.isEmpty() && current == flipped.top()) { counter ++; flipped.pop(); } info.push(counter); info.push(current); counter = 0; } return info; } public static Stack flipStack(Stack st) { Stack stFlipped = new Stack(); int first; while (!st.isEmpty()) { first = st.pop(); stFlipped.push(first); } return stFlipped; }