Clifford David
Addict
- Joined
- Jun 23, 2013
- Posts
- 20
- Reaction
- 16
- Points
- 68
- Age
- 27
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
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
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.