#include #include #include #define N_DFT 10 #define MAX_WT 99 typedef struct { int wt; char type; int idx; } hnode; typedef hnode *heap; void heapify ( heap H, int n, int i ) { int l, r, min; hnode t; while (1) { l = 2*i; r = 2*i+1; if (l > n) return; min = ((l == n) || (H[l].wt <= H[r].wt)) ? l : r; if (H[min].wt >= H[i].wt) return; t = H[i]; H[i] = H[min]; H[min] = t; i = min; } } void makeheap ( heap H, int n ) { int i; for (i=n/2; i>0; --i) heapify(H,n,i); } void insert ( heap H, int n, int wt, int k ) { int i, p; hnode h; h.wt = wt; h.type = 'G'; h.idx = k; H[(i = n+1)] = h; while (1) { if (i == 1) return; p = i / 2; if (H[p].wt <= H[i].wt) return; H[i] = H[p]; H[p] = h; i = p; } } void delete ( heap H, int n ) { H[1] = H[n]; heapify(H,n-1,1); } int *getweights ( int n ) { int *A, i; printf("n = %d\n", n); A = (int *)malloc(n * sizeof(int)); for (i=0; i= 2) n = atoi(argv[1]); else n = N_DFT; w = getweights(n); mineffort(w,n,1); mineffort(w,n,2); free(w); exit(0); }