Sunday, July 23, 2006

Giving you a glimpse of my Code

public void generate() {
show();//show the first combination
while(this.hasMore()) {
int
i = r - 1;

while(arr[i] == n - r + i) { //continue moving to the left
i--;
}
arr[i] = arr[i] + 1; //start incrementing

for (int j = i + 1; j < r; j++) {
arr[j] = arr[i] + j - i; // increment everything else to the right by 1;
}
show();//show the rest of the combinatio
}
}

This a code to generate combinations. It is based on Rose's algorithm of generating combinations. Its a very fast algorithm.... I guess It makes no sense posting this because its just a fragment of the whole class. But if you have questions, You can just mail me.. hehe

No comments: