我的排序功能有什么问题? [英] What is wrong with my sorting function?
本文介绍了我的排序功能有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void sort()
{
int i = 0,l = 0;
while(i< myclass.d_arr_size)
{
if(myclass.d_arr [i]< = myclass.d_arr [l])
{
myclass.d_arr [i] = myclass.d_arr [l];
i ++;
} else(l
code
]。
您应该交换值而不是只分配给 i
index。
这可能不是您代码中的唯一错误:)
It doesn't seem to sort all the numbers. Some totally disappear.
void sort ()
{
int i = 0, l = 0;
while(i < myclass.d_arr_size)
{
if(myclass.d_arr[i] <= myclass.d_arr[l])
{
myclass.d_arr[i] = myclass.d_arr[l];
i++;
} else (l < myclass.d_arr_size) ? (l++) : (l=0, i++);
}
}
What is wrong?
解决方案
myclass.d_arr[i] = myclass.d_arr[l];
You should swap values instead of just assigning to the i
index.
This may not be the sole bug in your code :)
这篇关于我的排序功能有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文