Bin Packing

    0

    0

    Giovanny Gongora

    Codiga's C Recipes

    Bin-Packing algorithm using next fit heuristics

    #include<stdio.h>
    
    void binPacking(int *a, int size, int n) {
      int binCount = 1, i;
      int s = size;
      for (i = 0; i < n; i++) {
        if (s - *(a + i) > 0) {
          s -= *(a + i);
          continue;
        } else {
          binCount++;
          s = size;
          i--;
        }
      }
      printf("Number of bins required: %d", binCount);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.