QuickSort

Language/C Language

int partition(int theList[], int start, int end)
{	int pivot = theList[end];                                       
    int bottom = start-1;                                                   
    int top = end;                                                           
    bool notdone = true;
    while (notdone)
	{
        while (notdone)
	{
            bottom += 1;                  
            if (bottom == top)   
	    {
                notdone = false;                        
                break;
	    }
            if (theList[bottom] > pivot)   
	     {
                theList[top] = theList[bottom];       
                break;
	     }
	}  
	while (notdone)
	{
            top = top-1;                      
            
            if (top == bottom) 
	    {
                notdone = false;                      
                break;
	     }
            if (theList[top] < pivot)
	    {   
                theList[bottom] = theList[top];
		break;
	     }      
	}
    }
    theList[top] = pivot;                          
    return top;
}//Actual function call within program
int quickSort(int theList[], int start, int end)
{	if (start < end)     
	{
             int split = partition(theList, start, end);   //recursion   
             quickSort(theList, start, split-1);         
             quickSort(theList, split+1, end); 
	}
        else
	{
             return 0;
	}
}

'Language > C Language' 카테고리의 다른 글

2-Way Merge Sort  (0) 2011.03.22
매크로 가드(Macro Guard)  (0) 2011.02.13
Hello world!  (0) 2011.02.07