以关键码序列(503,087,512,061,908,170,897,275,653,426)为例,手工执行以下排序算法,写出每一趟排序结束时的关键码状态: (1)直接插入排序; (2)希尔排序(增量d[1]=5); (3)快速排序; (4)堆排序; (5)归并排序; (6)基数排序。
时间: 2023-06-15 16:06:18 浏览: 116
(1) 直接插入排序:
第1趟排序: 087,503,512,061,908,170,897,275,653,426
第2趟排序: 087,503,512,061,908,170,897,275,653,426
第3趟排序: 061,087,503,512,908,170,897,275,653,426
第4趟排序: 061,087,503,512,908,170,897,275,653,426
第5趟排序: 061,087,170,503,512,908,897,275,653,426
第6趟排序: 061,087,170,503,512,897,908,275,653,426
第7趟排序: 061,087,170,503,512,897,908,275,653,426
第8趟排序: 061,087,170,275,503,512,897,908,653,426
第9趟排序: 061,087,170,275,426,503,512,897,908,653
(2) 希尔排序(增量d[1]=5):
第1趟排序: 170,087,512,061,426,503,897,275,653,908
第2趟排序: 170,087,512,061,426,503,897,275,653,908
第3趟排序: 170,061,512,087,426,503,908,275,653,897
第4趟排序: 061,087,170,275,426,503,512,653,897,908
第5趟排序: 061,087,170,275,426,503,512,653,897,908
(3) 快速排序:
第1趟排序: 426,087,512,061,275,503,170,897,653,908
第2趟排序: 170,087,275,061,426,503,512,897,653,908
第3趟排序: 087,061,170,275,426,503,512,897,653,908
第4趟排序: 061,087,170,275,426,503,512,897,653,908
(4) 堆排序:
第1趟排序: 908,087,897,061,653,170,512,275,503,426
第2趟排序: 653,512,897,275,503,170,087,061,426,908
第3趟排序: 512,503,897,275,426,170,087,061,653,908
第4趟排序: 503,426,897,275,061,170,087,512,653,908
第5趟排序: 426,275,897,061,503,170,087,512,653,908
第6趟排序: 275,170,897,061,426,087,503,512,653,908
第7趟排序: 170,087,897,061,275,426,503,512,653,908
第8趟排序: 087,061,653,170,275,426,503,512,897,908
第9趟排序: 061,087,503,170,275,426,512,653,897,908
(5) 归并排序:
第1趟排序: 087,503,512,061,170,275,426,897,653,908
第2趟排序: 061,087,170,275,426,503,512,653,897,908
第3趟排序: 061,087,170,275,426,503,512,653,897,908
(6) 基数排序:
第1趟排序: 170,061,503,512,275,087,897,653,426,908
第2趟排序: 061,087,170,275,426,503,512,653,897,908
第3趟排序: 061,087,170,275,426,503,512,653,897,908
第4趟排序: 061,087,170,275,426,503,512,653,897,908
第5趟排序: 061,087,170,275,426,503,512,653,897,908
阅读全文