Education Menu

 

Features Menu

 

Additional Menu

 

Now Online

We have 176 guests online
 

@edulanka

 

Follow US

Twitter You Tube Google Plus
Pinterest Facebook EduLanka Blog

 

Information Zone

eduLanka Sinhala

Welcome to eduLanka.LK, Largest online education web site in Sri Lanka & most popular educational web site among Sri Lankan students. EduLanka, Best nonprofit & educational website is provided large numbers of online lessons, education related course information, teachers information, E books, examination result alerts, goverment job alerts, tuition class information, career guide for school leavers and more resources related to education in Sri Lanka. Edulanka provides education related resources from primary education, O-Level & A-Level education, University & Postgraduate education and vocational training education.

EduLanka IDN Domains http://එඩියුලංකා.ලංකා http://எடியுலங்கா.இலங்கை


jobs Mathematics SLAS Exam Dharma Education Results



 

Inside Online School

Share Us

Home Page Information Technology Java Programing (ජාවා වැඩසටහන්කරණය)

Java Quick Sort Example and Code
Saturday, 19 March 2011 23:16

Java Quick Sort - Example and Smple Code

Quick Sort is very special and fast sorting algorthm. This is examle source code for Java Quick Sort Algorithm for Students who follows Java as a subject in any course. Java programing language codes Quick sort algorithm and many  of Java platforms available here with for improve your knowledge.

/*eduLanka Online education web site of Sri Lanka
  -------- w w w . e d u L a n k a . l k ------------
  java programs for University students - who follow courses  -  BIT  -  SLIIT and more
  find more lessons in http://www.edulanka.lk  This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  this programs under GNU licence
*/

import TerminalIO.*;

class QuickSort{
    public static void main(String []args){
       
        KeyboardReader input=new KeyboardReader();
       
        int n=input.readInt("enter list size : ");
        int[] Arr=new int[n];
        for(int i=0;i<n;i++)
        Arr[i]=input.readInt("enter elements :");
       
        int pivot1;
        pivot1=partition(Arr,0, n-1);
       
    System.out.println("Pivot Value is "+pivot1);
       
      
           quicksort(Arr, 0, n-1);
       for(int j=0; j<Arr.length ; j++)
              System.out.println(Arr[j]);
              }
      

public static void  quicksort(int array[], int left,int  right)
                            {
                    
                 int pivot =partition(array, left, right);
                 if (left<pivot)
                 quicksort(array, left, pivot-1);
                 if (right>pivot)
                 quicksort(array, pivot+1, right);
                 }
   
   
   
public static int partition(int numbers[],int left,int right){
   
    int I_hold,r_hold,i;
    int pivot;
    I_hold=left;
    r_hold=right;
   
    pivot=numbers[left];
    while(left<right){
       
        while((numbers[right]>=pivot)&&(left<right))
            right--;
                if(left!=right){
                numbers[left]=numbers[right];
                left++;
            }
       
                while((numbers[left]<=pivot)&&(left<right))
                    left++;
                    if(left!=right){
                    numbers[right]=numbers[left];
                    right--;
           
                }
            }   
       
        numbers[left]=pivot;
        pivot=left;
        left=I_hold;
        right=r_hold;
        return pivot;
}   

   
}

Download Full Code

 

Add comment

Add comments relevant to this Article. මෙම ලිපියට අදාලව පමණක් අදහස් එකතු කරන්න.


Security code
Refresh

16.jpg

Download Toolbar

 
 

Most Popular Articles

Latest Articles

Copyright © 2005 - 2016 (ඉස්කෝලේ) eduLanka Online Education School of Sri Lanka