#include <iostream>
#include 
<stdio.h>
using namespace std;

/***********************Quick Sort***************************/
//QS will be the Fastest; SS will be the best;  
int partition(int *num, int iLeft, int iRight)
{
    
int i = iLeft;
    
int j = iRight;
    
int iTemp = num[j];
    
    
while(i != j)
    {
        
while((i < j) && num[i] < iTemp) i++;
        
if(i < j)
        {
            num[j] 
= num[i];
            j
--;
        }
        
while((i < j) && num[j] > iTemp) j--;
        
if(i < j)
        {
            num[i] 
= num[j];
            i
++;
        }
    }   

    num[i] 
= iTemp;
    
return i;
}

void quicksort(int *num, int iLeft, int iRight)
{
    
if(iLeft >= iRight) return;
    
int iTemp = 0;
    iTemp 
= partition(num, iLeft, iRight);
    quicksort(num, iLeft, iTemp 
- 1);
    quicksort(num, iTemp 
+ 1, iRight);
}
/**********************************************************/

/***********************Bubble Sort************************/
void bubblesort(int *nums, int len)
{
    
int temp = 0;
    
for(int i = 0; i < len - 1; i++)
        
for(int j = 0; j < len - 1 - i; j++)
        {
            
if(nums[j + 1< nums[j])
            {
                temp 
= nums[j + 1];
                nums[j 
+ 1= nums[j];
                nums[j] 
= temp;       
            }
        }
}
/**********************************************************/

/***********************Shell Sort************************/
void Shellsort(int *nums, int len)
{
    
int d = len;
    
int temp;
    
while(d > 1)
    {
        d 
= (d + 1)/2;
        
for(int i = 0; i < len - d; i++)
        {
            
if(nums[i + d] < nums[i])
            {
                temp 
= nums[i + d];
                nums[i 
+ d] = nums[i];
                nums[i] 
= temp;                
            }
        }
    }
}
/**********************************************************/

void main()
{
    
int z = 9999;
    
int a[10= {102356734121135};
    
//quicksort(a, 0, 9);
    
//Shellsort(a, 10);
    bubblesort(a, 10);
    
for(int i = 0; i < 10; i++)
    {
        cout
<<a[i]<<endl;
    }
    cin
>>z;
}
posted on 2009-06-05 14:18  Jackill  阅读(108)  评论(0编辑  收藏  举报