不懂就问吧友
c吧
全部回复
仅看楼主
level 1
这里哪儿错了?
2022年11月21日 07点11分 1
level 1
冒泡排序错了还是随机函数错了[泪]
2022年11月21日 07点11分 2
level 10
堆上开数组, 一般用于长度由用户输入的情况。
冒泡单独拎出来,最好把长度也当参数传进去。
2022年11月23日 23点11分 3
level 10
随机数, cpp官网有现成的,随便找个写就行。只有C语言没办法,才用rand srand这两个。
2022年11月23日 23点11分 4
level 10
void maopao(int *arr, int n){
int temp;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (arr[j] > arr[j+1])
temp = arr[j],
arr[j] = arr[j+1],
arr[j+1] = temp;
}
2022年11月23日 23点11分 5
level 10
当然了,还有许多优化的地方,像指针要换成 shared_ptr,指针参数用引用等待。你自己琢磨吧。
2022年11月24日 00点11分 6
level 10
如果不想学新东西,只想搞C的话。
======================
int max = 11111;
srand(time(NULL));
for ( ...)
arr[i] = rand() % max + 1000;
======================
改成这样就好了,得到 [1000, 11111) 之间的随机数
2022年11月24日 00点11分 7
1