Running Time of Algorithms

  • + 0 comments

    here is my solution

    public static int runningTime(ArrayList<Integer> a) {
            int count = 0;
            for (int i = 1; i < a.size(); i++) {
                if (a.get(i) < a.get(i - 1)) {
                    int temp = a.get(i);
                    a.set(i, a.get(i - 1));
                    a.set(i - 1, temp);
                    count++;
                    i = 0;
                }
            }
            return count;
        }