# How to count quicksort compares and swaps

```package myAlgorithmCounts; import java.util.*; public class QuickSortRun {   private static int counterOne = 0;   private static int counterTwo = 0;   private static int counterThree = 0;   private static int counterFour = 0;   int[] list3;   public void QuickSortRun(int array[], int low, int n)   {     int lo = low;     int hi = n;     if (lo >= n)     {       return;     }     int mid = array[(lo + hi) / 2];     while (lo < hi)     {       while (lo < hi && array[lo] < mid)       {         lo++;       }       while (lo < hi && array[hi] > mid)       {         hi--;       }       if (lo < hi)       {         int T = array[lo];         array[lo] = array[hi];         array[hi] = T;       }       counterOne++;     }     if (hi < lo)     {       int T = hi;       hi = lo;       lo = T;     }     QuickSortRun(array, low, lo);     QuickSortRun(array, lo == low ? lo + 1 : lo, n);     list3 = Arrays.copyOf(array, n + 1);   }   public void displayList()   {     for (int i = 0; i < list3.length; i++)     {       System.out.print(" " + list3[i]);     }     System.out.println();   }   public int getCounterOne()   {     return counterOne;   }   public void setCounterOne(int counterOne)   {     QuickSortRun.counterOne = counterOne;   }   public int getCounterTwo()   {     return counterTwo;   }   public void setCounterTwo(int counterTwo)   {     QuickSortRun.counterTwo = counterTwo;   }   public int getCounterThree()   {     return counterThree;   }   public void setCounterThree(int counterThree)   {     QuickSortRun.counterThree = counterThree;   }   public int getCounterFour()   {     return counterFour;   }   public void setCounterFour(int counterFour)   {     QuickSortRun.counterFour = counterFour;   } }```