예제 #1
0
void partitionAll(int value)
{
  int *partition = malloc(sizeof(int) * value);
  partitionAllHelper(value, partition, 0);
  free(partition);

}
예제 #2
0
void partitionAllHelper(int budget, int *partition, int pos)
{

  //BASE CASE!!!
  if (budget == 0){
    printpartition(partition, pos);
    return;
  }
  

  //INDUCTIVE CASE!!!!!
  int spending;
  for(spending = 1; spending <= budget; spending+= 1){
    partition[pos] = spending;
    partitionAllHelper(budget - spending, partition, pos + 1);
  }
}
예제 #3
0
void partitionAllHelper(int N, int *partition, int pos)
{
	//BASE CASE	
	if(N == 0)
	{
	printPartition(partition, pos);
	return;
	}

	//INDUCTIVE CASE	
	int i;
	for(i = 1; i <= N; i++)
	{
	partition[pos] = i;
	partitionAllHelper(N - i, partition, pos + 1);
	}

}