## Infosys Interview Question for Java Developers

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public class QuickSort{
public static void main(String args[]){
int array[] = {12,9,4,99,120,1,3,10,13};
quick_srt(array,0,array.length-1);
}

public static void quick_srt(int array[],int low, int n){
int lo = low;
int hi = n;
if (lo >= n) {
return;
}
int mid = array[(lo + hi) / 2];
while (lo < hi) {
while (lo<hi && array[lo] < mid) {
lo++;
}
while (lo<hi && array[hi] > mid) {
hi--;
}
if (lo < hi) {
int T = array[lo];
array[lo] = array[hi];
array[hi] = T;
}
}
if (hi < lo) {
int T = hi;
hi = lo;
lo = T;
}
quick_srt(array, low, lo);
quick_srt(array, lo == low ? lo+1 : lo, n);
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

You can get complete program under this link

Comment hidden because of low score. Click to expand.
0
of 0 vote

find full code here

javahungry.blogspot.com/2013/06/java-sorting-program-code-quick-sort.html

Comment hidden because of low score. Click to expand.
0
of 0 vote

In C# :
public int Partition(int[] a,int left,int right)
{
int pivot=a[left];
while(true)
{
while(a[left]<pivot)
left++;
while(a[right]>pivot)
right--;
if(left<right)
{
int temp=a[right];
a[right]=a[left];
a[left]=temp;
}
else
return right;

}

{
public int[] QuickSort(int[] a, int left,int right)
{
int pivot=Partition(a,left,right);
if(pivot>left)
QuickSort(a,left,pivot-1);
if(pivot<right)
QuickSort(a,pivot+1,right);

return a;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

In C# :
public static int Partition(int[] a ,int left,int right)
{
int pivot = a[left];
while(true)
{
while (a[left] < pivot)
left++;
while (a[right] > pivot)
right--;
if(left<right)
{
int temp = a[right];
a[right] = a[left];
a[left] = temp;
}
else
{
return right;
}
}
}
public static void QuickSortRecur(int[] a ,int left, int right)
{
if(left<right)
{
int pivot = Partition(a, left, right);
//Console.Write(pivot);
if (pivot >left)
QuickSortRecur(a, left, pivot-1);
if (pivot < right)
QuickSortRecur(a, pivot+1, right);

}
}

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.