您的位置:首页 > 编程语言 > C语言/C++

c语言实现冒泡排序

2018-01-06 22:28 405 查看
#include
<stdio.h>
#include
<string.h>
 
char
 
words[10][6]={
"dszcr"
,
"dwcrg"
,
"cueuz"
,
"nufas"
,
"rgvzu"
,
"fesiu"
,
"fwehs"
,
"dqhzo"
,
"woajz"
,
"hgruk"
};
char
*
temp[10];
void
 
sort();
void
 
sortonce(
char
 
*strings[],
int
 
num)
{
    
char
 
*temp;
    
int
 
top
,seek;
    
//对字符串指针进行排序
    
for
 
(top=0;
top< num-1;top++ )
        
for
 
(seek
= top+1;seek<num;seek++)
        
//对字符串进行比较strcmp
            
if
(
strcmp
(strings[top]
,strings[seek] ) > 0)
            
//交换排序
            
{
                
temp
= strings[top];
                
strings[top]
= strings[seek];
                
strings[seek]=
temp;
            
}
}
 
void
 
sort()
{
    
int
 
i,j;
    
for
 
(i=0;i<=9;i++)
temp[i]=words[i];
    
sortonce(temp,10);
}
 
int
 
main()
{
    
int
 
i;
    
sort();
    
for
 
(i=0;i<=9;i++)
{
        
printf
(
"%s,"
,temp[i]);
    
}
    
return
 
0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 学习