« Home | Bubble Sort » | Program for print Ramanjan Numbers » | Overriding in java » | What is overloading in java » | Program to reverse a string » | XML Parser in Java » | Algorithms Used in Garbage collection » | Lower Case to Uppre Case Conversion » | PRINTING THE NON-PRIMES » | PRIME FACTORS OF ALL NON-PRIMES BELOW 500 » 

Monday, April 10, 2006 

Program to Implement Quick Sort

/**
The quick sort is an in-place, divide-and-conquer, massively recursive sort. The efficiency of the algorithm is majorly impacted by which element is choosen as the pivot point.The worst-case efficiency of the quick sort, O(n2), occurs when the list is sorted and the left-most element is chosen.*/

Pros: Extremely fast.
Cons: Very complex algorithm, massively recursive.

#include
#include



void quickSort(int numbers[], int array_size);
void q_sort(int numbers[], int left, int right);

int numbers[5];


int main()
{
int i;

printf("Enter the numbers to be sorted");
for (i = 0; i <5; i++)
scanf("%d",&numbers[i]);

//perform quick sort on array
quickSort(numbers, 5);

printf("List of Elements after Sorting.\n");
for (i = 0; i < 5; i++)
printf("%i\n", numbers[i]);
}


void quickSort(int numbers[], int array_size)
{
q_sort(numbers, 0, array_size - 1);
}



void q_sort(int numbers[], int left, int right)
{
int pivot, l_hold, r_hold;
static int count=0;
count++;
l_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 = l_hold;
right = r_hold;
if (left < pivot)
q_sort(numbers, left, pivot-1);
if (right > pivot)
q_sort(numbers, pivot+1, right);
}

WILL U PLEASE CINVERT THIS PROGRAM INTO JAVA CODE BY NOT USING MORE THAN 2 CLASSES& IMPLEMENT IT BY RECURSION

PLEASE MIL YOUR PROGRAM TO b.rajesh462@gmail.com AS EARLY AS POSSIBLE. THANKING U,
YOURS FAITHFULLY,
B.Rajeswara Reddy.

Post a Comment

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com