#includestruct Bag { int BagID; int BagWeight; int BagPrice; int SinglePrice; float Num; }; void seekBest(Bag bag[],int n,float bagRL) { int i; float BRL=bagRL; for(i=0;i BRL) break; else { bag[i].Num=1; BRL=BRL-bag[i].BagWeight; } } if(i<=n) { bag[i].Num=BRL/bag[i].BagWeight; } for(i=0;i 0) { printf("放入ID號為:%d 重量為 %d 的物品 %f 件!!!\n\n",bag[i].BagID,bag[i].BagWeight,bag[i].Num); } } } void Sort(Bag bag[],int n) { int j; Bag temp; int i; for(i=0;i #include #define N 50 struct Object { int list; // 物體的編號 float p; // 物體的價值 float w; // 物體的重量 float v; // 物體的價值重量比 }; void MERGE(Object A[],int low,int mid,int high) { int h,i,j,k; Object* B=(Object*)malloc((high-low+1)*sizeof(Object)); h=low; i=0; j=mid+1; while (h<=mid && j<=high) { if (A[h].v>=A[j].v ) { B[i]=A[h]; h=h+1 ; } else { B[i] =A[j]; j=j+1 ; } i++; } if( h>mid) { for (k=j;k<=high;k++) { B[i]=A[k]; i=i+1; } } else for (k=h;k<=mid;k++) { B[i] =A[k]; i=i+1; } i=0; for (k=low;k<=high;k++) { A[k] =B[i] ; i++; } free(B); } void MERGESORT(Object array[],int low,int high) { int mid; if( low >m; cout<<"請輸入物體的個數:"; cin>>n; cout<<"請輸入物體的價格、重量:"< >instance[i].p>>instance[i].w; cout<<"--------------------------------------"<