1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

Java Java Programming - other Sorting Program

Discussion in 'Coding, Programming' started by Clifford David, Mar 16, 2014.

  1. Hi Guys! kailangan kasi namin ng program.. pede ba kau mag suggest ng ibang codes regarding sorting.

    class SortQuick
    {
    public static void main(String[] args)
    {
    int i;
    int array[] = {12,9,4,99,1};
    System.out.println("Elements Before Sort:\n");
    for(i = 0; i < array.length;i++)
    System.out.print(array+" ");
    System.out.println();
    quickSort(array,0,array.length-1);
    System.out.println("Elements Before Sort:\n");
    for(i = 0;i<array.length;i++)
    System.out.print(array+" ");
    System.out.println();
    }
    public static void quickSort(int a[],int low,int len)
    {
    if(low>=len)return;
    int l=low,n=len;
    int piv=a[(l+n)/2];
    while(l<n)
    {/**
    moving upto less than pivot value from start.*/
    while(l<n&&a[l]<piv)
    l++;
    /**
    moving upto greater than pivot value from end*/
    while(l<n&&a[n]>piv)
    n--;
    /**
    swap in order to move least elements to left and maximum to right of the pivot*/
    if(l<n)
    {
    int tem = a[l];
    a[l]=a[n];
    a[n]=tem;
    }//end of while loop ------------1
    if(n<l)//Checkingstart and end index(start must be less than end otherwise swap)
    {
    int t = l;l=n;n=t;
    }
    quickSort(a,low,l);
    quickSort(a,l==low?l+1:l,len);
    }
    }
    }

    I need Program other than this Thanks :)
     

    Attached Files:

    You must or Register to view Attachment.
  2. JhoLou

    JhoLou Eternal Poster Established

    Lemme try this ts hoho. (y)
     
    Ronald Caracena likes this.
  3. Causing Glenn

    Causing Glenn daemonX Staff Member Moderator

    _if you want java langugage, meron na dyan built-in sorting algo... tatawagin mo nalang ang method nya tapos agad.
     
    Ronald Caracena likes this.
  4. Simple Sorting algo: Bubble Sort, Selection sort, Insertion sort.
    Advance Sorting : Radix Sort, Shell Sort, Quick Sort.
     
  5. implement Merge Sort


    Code:

       Sorry you need to Register / Login to see this Codes!    

     
    JhoLou likes this.
Tags / Keywords: