-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
28 lines (19 loc) · 788 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include "knapsack.h"
int main(int argc, char **argv) {
int target = atoi(argv[1]);
int length = argc - 2; // minus 2 because argc includes command to execute program and target value, which are not elements of the set
int set[length];
parseSet(set, argv, length);
// printSet(set, length, isSubset?[0(no, 1(yes))])
printSet(set, length, 0);
printf("target = %d\nlength = %d\n", target, length);
if(unsorted(set, length)) { selectionSort(set, length); }
int s[length]; // for *subset initialisation
// findSubset(set, subset, length, target, sum, index, takeCount);
int *subset = findSubset(set, s, length, target, 0, 0, 0);
if(subset == 0) { printf("no subset found\n"); }
else { printSet(subset, length, 1); }
return 0;
}