北大青鸟培训机构:问个有关C语言的编程题,哪位好心人帮我编一下

来源:百度文库 编辑:高校问答 时间:2024/04/29 11:25:56
编程:在主函数中输入5个字符串,用另一函数对它们进行排序,然后在主函数中输出排好序的字符串(用字符数组存储字符串,采用冒泡排序法或选择排序法

这种问题?

JAVA的
public void bubbleSort(int a[]) { //数组的冒泡排序
int n = a.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}

public void selectSort(int a[]) { //数组的选择排序
for (int n = a.length; n > 1; n--) {
int i = max(a, n);
int temp = a[i];
a[i] = a[n - 1];
a[n - 1] = temp;
}
}