AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: hkartika — October 6, 2006
    -8 votes
      + -

    use a stack

  2. Submitted By: vikramjits — October 6, 2006
    +1 votes
      + -

    An array can be sorted using any of the classic algorithms like quicksort , heapsort and the inefficient bubblesort.

  3. Submitted By: TimeHawk — October 6, 2006
    -1 votes
      + -

    For use with strings and int/floats/doubles

    while (!sorted)
    {
    sorted=true;
    for(int i=1; i<size; i++)
    {
    if(arr[i]<arr[i-1])
    {
    sorted=false;
    tmp=arr[i];
    arr[i]=arr[i-1];
    arr[i-1]=tmp;
    }
    }
    }

  4. Submitted By: Moez — October 6, 2006
    -7 votes
      + -

    int[] arraySort(int[] arr, int len)
    {
    for (int i=0;i<len;i++)
    {
    if(arr[i]>arr[j])
    {
    int buf=arr[i];
    arr[i]=arr[j];
    arr[j]=buf;
    }
    }
    return arr;
    }

    Simple Insertion Sort.

  5. Submitted By: Moez — October 6, 2006
    +3 votes
      + -

    Sorry in last solution forgot to add a loop. Here is the correct solution.

    int[] arraySort(int[] arr, int len)
    {
    for (int i=0;i<len;i++)
    {
    for (int j=i+1; j<len; j++)
    {
    if(arr[i]>arr[j])
    {
    int buf=arr[i];
    arr[i]=arr[j];
    arr[j]=buf;
    }
    }
    return arr;
    }

    Simple Insertion Sort.

  6. Submitted By: matty — October 6, 2006
    not yet rated
      + -

    Use a quick sort if it is a fairly large array , other wise a merge sort should solve the purpose.

  7. Submitted By: harpreet — October 6, 2006
    +1 votes
      + -

    Try this,

    void sortarray(int *ar, int len)
    {

    for (int i=0 ;i < len; i++)
    {
    for (int j =i+1 ;j < len ;j++)
    if(ar[j]< ar[i])
    {
    int tmp = ar[i];
    ar[i] = ar[j];
    ar[j] =tmp;
    }
    }

    //print to test (after sorting)
    for(int i =0 ;i < len ;i++)
    cout<< ar[i] << “n”;

    }

  8. Submitted By: chip2812 — October 6, 2006
    -2 votes
      + -

    i remmeber reading somewhere that heapsort is the best for arrays, or is it that heapsort can only be used for arrays?

  9. Submitted By: jijiduru — March 8, 2007
    +2 votes
      + -

    What is the matter with you people? That’s not insertion sort.. it’s plain old stupid bubble sort.

  10. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.