0% found this document useful (0 votes)
2 views2 pages

Quick Sort Implementation in Java

Uploaded by

athirasuresh235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Quick Sort Implementation in Java

Uploaded by

athirasuresh235
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#LBT22CS046 S3CS146 ELIZABETH REJI

# PROGRAM TO IMPLEMENT QUICK SORT

import [Link];

class SortQ

public static void quickSort(String A[],int p,int r)

if(p<r)

int q = partition(A,p,r);

quickSort(A,p,q-1);

quickSort(A,q+1,r);

public static int partition(String A[],int p,int r)

String x = A[r];

int i = p-1;

for(int j=p;j<=r-1;j++)

if(A[j].compareTo(x) <=0)

i = i + 1;

String temp = A[i];

A[i] = A[j];

A[j] = temp;

String temp = A[i+1];

A[i+1] = A[r];
A[r] = temp;

return i +1 ;

public static void main(String args[])

Scanner sc = new Scanner([Link]);

[Link]("Enter the limit:");

int n = [Link]();

[Link]();

String A[] = new String[n];

[Link]("Enter the names");

for(int i =0;i<n ;i++)

A[i] = [Link]();

quickSort(A,0,n-1);

[Link]("After Quick Sort");

for(int i =0;i<n;i++)

[Link](A[i]);

You might also like