C++ Program to Implement First Fit Decreasing for 1-D Objects and M Bins

Here is a C++ Program to implement First Fit Decreasing for 1-D objects and M bins

Required functions and pseudocode:

Begin
   function binPack() returns number of bins required.
   Initialize binC = 0
   Initialize an array to store binVal.
   Place items one by one.
   function sort() to perform bubble sort in the descending order.
End

Example Code

#include 
using namespace std;
void binPack(int *a, int s, int n)
{
   int binC = 0;
   int binVal[n];
   for (int i = 0; i = 0)
      {
         binVal[j] -= a[i];
         break;
      }
   }
   for (int i = 0; i > n;
   cout > a[i];
   cout > s;
   int *seq = sort(a, n);
   binPack(seq, s, n);
}

Output

Enter the number of items in Set: 7
Enter 7 items:4
6
7
5
3
2
1
Enter the bin size: 5
Number of bins required using first fit decreasing algorithm is: 3
Updated on: 2019-07-30T22:30:25+05:30

227 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements