public static List <Folder> worstFitDecreasingLS(List <AudioFile> input, int maxcap) { // sort the input using the built-in list sorting method //input.Sort((x, y) => -1 * x.Duration.CompareTo(y.Duration)); // convert the input list to an array AudioFile[] inputArray = input.ToArray(); MinHeap.HeapSort(inputArray); //O(Nlog(N)) List <Folder> myFolders = new List <Folder>(); Folder firstFolder = new Folder(maxcap); myFolders.Add(firstFolder); for (int i = 0; i < inputArray.Length; i++) { int max_remain_cap = 0; Folder max_remain_folder = null; for (int j = 0; j < myFolders.Count; j++) { if (myFolders[j].remaincap > max_remain_cap) { max_remain_cap = myFolders[j].remaincap; max_remain_folder = myFolders[j]; } } if ((max_remain_folder != null) && (max_remain_folder.remaincap >= (int)inputArray[i].Duration.TotalSeconds)) { max_remain_folder.addFile(inputArray[i]); } else { Folder folder = new Folder(maxcap); folder.addFile(inputArray[i]); myFolders.Add(folder); } } return(myFolders); }
public static LinkedList <Folder> worstFitDecreasingLS(List <AudioFile> input, int maxcap) { // convert the input list to an array AudioFile[] inputArray = input.ToArray(); MinHeap.HeapSort(inputArray); //O(Nlog(N)) LinkedList <Folder> myFolders = new LinkedList <Folder>(); Folder firstFolder = new Folder(maxcap); myFolders.AddLast(firstFolder); for (int i = 0; i < inputArray.Length; i++)//O(N) { int max_remain_cap = 0; Folder max_remain_folder = null; LinkedListNode <Folder> current = myFolders.First; for (int j = 0; j < myFolders.Count; j++)//O(M) { if (current.Value.remaincap > max_remain_cap) { max_remain_cap = current.Value.remaincap; max_remain_folder = current.Value; } current = current.Next; } if ((max_remain_folder != null) && (max_remain_folder.remaincap >= (int)inputArray[i].Duration.TotalSeconds)) { max_remain_folder.addFile(inputArray[i]); } else { Folder folder = new Folder(maxcap); folder.addFile(inputArray[i]); myFolders.AddLast(folder); } } return(myFolders); }
public static List <Folder> folderFilling2(List <AudioFile> input, int maxcap) { AudioFile[] inputArray = input.ToArray(); MinHeap.HeapSort(inputArray); //O(Nlog(N)) return(folderFilling(inputArray.ToList <AudioFile>(), maxcap)); }
public static List <Folder> bestFitDecreasingLS(List <AudioFile> input, int maxcap) { AudioFile[] inputArray = input.ToArray(); MinHeap.HeapSort(inputArray); //O(Nlog(N)) return(bestFitLS(inputArray.ToList <AudioFile>(), maxcap)); }