public static <E extends Comparable<? super E>> Stack<E> sort(Stack<E> input) {
        Stack<E> s1 = new Stack<>();

        while (!input.isEmpty()) {
            E e = input.pop();
            if (s1.isEmpty() || (e.compareTo(s1.peek()) >= 0)) {
                s1.push(e);
            } else {
                int count = 0;
                while (!s1.isEmpty() && (e.compareTo(s1.peek()) < 0)) {
                    input.push(s1.pop());
                    count++;
                }
                s1.push(e);
                moveAll(input, s1, count);
            }
        }
        return s1;
    }