Optimal Storage on Tapes | CPP Program to find the order of programs for which MRT is minimized ; This functions outputs the required order and Minimum Retrieval Time ; Here length of i 'th program is L[i] ; Lengths of programs sorted according to increasing lengths . This is the order in which the programs have to be stored on tape for minimum MRT ; MRT - Minimum Retrieval Time ; Driver Code to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findOrderMRT ( int L [ ] , int n ) { sort ( L , L + n ) ; cout << " Optimal ▁ order ▁ in ▁ which ▁ programs ▁ are ▁ to ▁ be " " stored ▁ is : ▁ " ; for ( int i = 0 ; i < n ; i ++ ) cout << L [ i ] << " ▁ " ; cout << endl ; double MRT = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j <= i ; j ++ ) sum += L [ j ] ; MRT += sum ; } MRT /= n ; cout << " Minimum ▁ Retrieval ▁ Time ▁ of ▁ this " " ▁ order ▁ is ▁ " << MRT ; } int main ( ) { int L [ ] = { 2 , 5 , 4 } ; int n = sizeof ( L ) / sizeof ( L [ 0 ] ) ; findOrderMRT ( L , n ) ; return 0 ; }