[C] 纯文本查看 复制代码
int main(int argc, const char * argv[])
{
int arr[6] = {1,23,44,56,78,0};
int len =sizeof(arr)/sizeof(arr[0]);
for (int i = 0; i < len; i++)
{
for (int j = 0; j < len - i -1; j++)
{
if(arr[j]<arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1]=temp;
}
}
}
for (int i = 0; i < len; i++)
{
printf("%d\n",arr);
}
return 0;
}
[C] 纯文本查看 复制代码
int arr[2][3] = {1,23,44,56,78,0};
int* arrP = (int*)&arr;
int len =sizeof(arr)/sizeof(int);
int temp;
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len - i -1; j++)
{
if( arrP[j] > arrP[j+1] )
{
temp = arrP[j];
arrP[j] = arrP[j+1];
arrP[j+1] = temp;
}
}
}
for (int i = 0; i < len; i++)
{
printf("%d\n",arrP);
}