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);
    }
  }

- tarek.salah@badrit.com November 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can get complete program under this link

javadiscover.com/2013/11/quicksort-in-java.html

- Kannan November 28, 2013 | Flag Reply
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

- Javalearner November 28, 2013 | Flag Reply
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;
}

- Anonymous February 19, 2016 | Flag Reply
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);

}
}

- Bhavs February 19, 2016 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More