数据结构作业
第三次:第一题
第三次:第二题
第三次:第二题:"matrix.txt"
第三次:第三题
第三次:第三题:“matrix2.txt”
第四次:题目说明
数据结构第七章章节测试
第四次:第一题
第四次:第二题:shell_sort
第四次:第二题:quick_sort
第四次:第二题:merge_sort
本文档使用 MrDoc 发布
-
+
首页
数据结构第七章章节测试
选择:bdcaacdcbbabcbac 填空: 1、A[Child]<A[Child+1] X<A[Child] A[Parent]=X PercDown(A,0,i) 2、2 3、简单插入排序 4、简单插入排序 5、堆 6、堆 快速 归并 7、j<=n-i-1 r[j]< r[mini] mini != i maxi == i 判断: 错错错对错对错错错对 简答:    最后一题: ```c #include <stdio.h> #include "stdlib.h" #include "malloc.h" void HeapSort(int a[], int n); void HeapAdjust(int a[], int m, int n); int main(){ // main function . int N, M, i, j, tmp,check; int * Monopoly; printf("Please input N and M( poosition of element to delete ) : "); scanf("%d %d", &N, &M); Monopoly = (int *)malloc(sizeof(int) * N); printf("Then, input them : \n"); for(i = 0; i < N; i++){ j = i + 1; scanf("%d", &Monopoly[i]); while(j != 1){ if(Monopoly[j - 1] > Monopoly[(j / 2) - 1]){ tmp = Monopoly[j - 1]; Monopoly[j - 1] = Monopoly[(j / 2) - 1]; Monopoly[(j / 2) - 1] = tmp; } else{ break; } j = j / 2; } } // check the input max_heap printf("Initial max_heap :\n"); for(check = 0; check < N; check++){ printf("%d ", Monopoly[check]); } printf("\n"); // heap_sort // HeapSort(Monopoly, N); tmp = Monopoly[M - 1]; Monopoly[M - 1] = Monopoly[N - 1]; Monopoly[N - 1] = tmp; HeapAdjust(Monopoly, M - 1, N - 2); // check the result printf("Result heap :\n"); for(check = 0; check < N; check++){ printf("%d ", Monopoly[check]); } return 0; } void HeapAdjust(int a[], int m, int n){ int i; int t = a[m]; for(i = 2 * m;i <= n;i = 2 * i){ if(i < n && a[i + 1] > a[i]) ++i; if(t >= a[i]) break; a[m] = a[i]; m = i; } a[m] = t; } ```
cdcdcd
2022年12月8日 22:26
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码