Quicksort Java code

package lab3;

/**
 *
 * @author ying
 */
public class No2 {
   
    public static void main(String[] args){
        int[] L={8,14,3,9,11,5,10,1,2,6,7,15,12,0,4,13};
        SortArray LL=new SortArray(L);
        LL.quicksort(0,15);
        for(int i=0;i<L.length;i++){
            System.out.print(LL.L[i]+” “);
        }
       
       System.out.println(“\nNo. of comparation is “+LL.count);
       
     
    }
    /** Creates a new instance of No2 */

}

class SortArray{
   public int L[];
   public int count=0;
    SortArray(int[] L){
        this.L=L;
       
    }
   public void quicksort(int first,int last){
        if(first<last){
        int splitpoint=split(first,last);
        quicksort(first,splitpoint-1);
        quicksort(splitpoint+1,last);
        }
    }
    public int split(int first,int last){
        int x=L[first];
        int splitpoint=first;
        for(int i=first+1;i<=last;i++){
            count++;
            if(L[i]<x){
                splitpoint++;
                interchange(splitpoint,i);
            }
              
        }
        interchange(first,splitpoint);
        return splitpoint;
    }
   
    public void interchange(int x,int y){
        int temp = L[x];
        L[x]=L[y];
        L[y]=temp;
    }
}

Insertion sort Java code

package lab3;
import javax.swing.*;

/**
 *
 * @author student
 */
public class No1 {
   
 public static void main(String[] args){
    int[] L={8,14,3,9,11,5,10,1,2,6,7,15,12,0,4,13};
    int n=L.length,count=0;
    int x,j;
     for(int xindex=1;xindex<n;xindex++){
         x=L[xindex];
         j=xindex-1;
         count++;
     while(j>=0 &&L[j]>x){
        L[j+1]=L[j];
        j–;
        if(j>=0)
        count++;

     }
        L[j+1]=x;
     }
    String output=””;
    for(int i=0;i<n;i++){
        output+=L[i]+” “;
    }
    JOptionPane.showMessageDialog(null,output+”\nNo. of comparation is “+count+” times”);
 }
   
}