#define SIZE 10
int arr[SIZE] = {1, 4, 3, 5, 2, 7, 8, 6, 9, 0};
int i;
int j;
for (i = 0; i< SIZE - 1; i++)
{int iMin = i;
for (j = i + 1; j< SIZE; j++)
{ if (arr[iMin] >arr[j]) { iMin = j;
}
}
int temp = arr[i];
arr[i] = arr[iMin];
arr[iMin] = temp;
}
BubbleSort#define SIZE 10
int arr[SIZE] = {1, 4, 3, 5, 2, 7, 8, 6, 9, 0};
int i, j;
for (i = 0; i< SIZE -1; i++)
{for (j = i + 1; j< SIZE; j++)
{ if (arr[i] >arr[j]) { int temp = arr[i] ;
arr[i] = arr[j];
arr[j] = temp;
}
}
InsertionSort#define SIZE 10
int arr[SIZE] = {1, 4, 3, 5, 2, 7, 8, 6, 9, 0};
int i, j;
for (i = 0; i< SIZE -1; i++)
{for (j = i + 1; j< SIZE; j++)
{ if (arr[i] >arr[j]) { int temp = arr[i] ;
arr[i] = arr[j];
arr[j] = temp;
}
while(i - 1 >= 0 && arr[i]< arr[i - 1])
{ int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
}
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧