posts - 0,  comments - 0,  trackbacks - 0

 

void BubbleSort( char* str, int strLen )
{
    
int temp = 0;
    
bool exchange = false;

    
forint i = strLen - 1; i > 0; i-- )
    {
        exchange 
= false;
        
forint m = 0; m <= i - 1; m++ )
        {
            
if( str[m] > str[m + 1] )
            {
                temp 
= str[m + 1];
                str[m 
+ 1= str[m];
                str[m] 
= temp;

                exchange 
= true;
            }
        }

        
if!exchange )
            
return;
    }
}

void BubbleSort( char* str, int strLen )
{
    
int temp = 0;

    
forint i = strLen - 1; i >= 0; i-- )
    {
        
forint m = 0; m < i; m++ )
        {
            
if( str[i] < str[m] )
            {
                temp 
= str[i];
                str[i] 
= str[m];
                str[m] 
= temp;
            }
        }
    }
}
posted on 2010-10-10 14:04 大喜头 阅读(81) 评论(0)  编辑 收藏 引用 所属分类: Default Category

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理