Ask Experts Questions for FREE Help !
Ask
    adil_chaudhry's Avatar
    adil_chaudhry Posts: 1, Reputation: 1
    New Member
     
    #1

    Apr 11, 2013, 08:35 PM
    help to fix this please
    This is what I have so far for quick sort but its keep giving me error. Can someone please help me Thanks



    public class Sorting{

    private static void swap (Comparable[] data, int index1, int index2)
    {
    Comparable temp = data[index1];
    data[index1] = data[index2];
    data[index2] = temp;
    }

    public static void insertionSort (Comparable[] data)
    {
    for (int index = 1; index < data.length; index++) {
    Comparable key = data[index];
    int position = index;

    while (position > 0 && data[position-1].compareTo(key) > 0) {
    data[position] = data[position-1];
    position--;
    }

    data[position] = key;
    }
    }

    public static void quickSort (Comparable[] data, int min, int max)
    {
    int pivot;

    if (min < max)
    {
    pivot = partition (data, min, max); // make partitions
    quickSort(data, min, pivot-1); // sort left partition
    quickSort(data, pivot+1, max); // sort right partition
    }
    }
    //-----------------------------------------------------------------
    // Creates the partitions needed for quick sort.
    //-----------------------------------------------------------------
    private static int partition (Comparable[] data, int min, int max)
    {
    // Use first element as the partition value
    Comparable partitionValue = data[min];

    int left = min;
    int right = max;

    while (left < right)
    {
    // Search for an element that is > the partition element
    while (data[left].compareTo(partitionValue) <= 0 && left < right)
    left++;

    // Search for an element that is < the partitionelement
    while (data[right].compareTo(partitionValue) > 0)
    right--;

    if (left < right)
    swap(data, left, right);
    }

    // Move the partition element to its final position
    swap (data, min, right);

    return right;
    }
    }

Check out some similar questions!

How to fix my ac [ 0 Answers ]

My apartment blows out cool air I put it on 63 degrees but my room temperature is saying 80 degrees up stairs is pretty hot down stairs cool but you cn tell its still hot manice came and worked on it but a week later it became doing the same thing again what should I do?

Fix TV [ 0 Answers ]

I have a 66" panasonic big screen, model pt-616cx35, serial number ggaa10569. Ok the problem is that the screen will not show the whole picture, the picture is off to the right. What can the problem be?

Hole in trunk; to fix or not to fix? [ 1 Answers ]

I have a massive Catalpa (sp) tree in my front yard. The trunk is about 4 feet in diameter at ground level. About 10 feet up the trunk, there is an oblong hole that's about 10" tall by 4" wide. I think squirrels are living in there. While I don't want to harm the squirrels, I don't want to lose...

Can I fix hazardous steps if a contractor is refusing to fix, and threatens to sue? [ 1 Answers ]

I live in central Texas. I hired a landscape contractor to install retaining walls and a patio which included 4 steps in stone. These steps range in size from 6.5" to 9.5" and the tallest is on the top! They are very dangerous. He refuses to do any fixes, and walked off project. At one point in the...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.