int main(void) { int num[10] = { 0 }; int times; printf("請輸入數字個數:"); scanf("%d", ×); for (int i = 1; i <= times; i++) { printf("請輸入數字:"); scanf("%d", &num[i - 1]); } sequence(num, times); dumparray(num, times); for (int i = 1; i < times; i++) { if (i == 1) { perm(num, i, times, times); } else { while (num[i - 1] == num[0]) { i++; } perm(num, i, times, times); } } }
void bmpcolortable::read(int bitsperpixel, FILE *fp) { switch (bitsperpixel) { case 1: numcolors = 2; break; case 4: numcolors = 16; break; case 8: numcolors = 256; break; default: assert(false); // should not be here } fread(&array, 4 * numcolors, 1, fp); dumparray(); }
void perm(int arr[], int start, int end, int times) { if (end == start||start<1) { return; } else { perm(arr, start, end - 1, times); counter ++; if (arr[start - 1] != arr[end - 1]) { swap(arr[start - 1], arr[end - 1]); dumparray(arr, times); if (start == counter ) { perm(arr, start , end-1, times); } else { perm(arr, start - 1, end, times); } } swap(arr[start - 1], arr[end - 1]); counter--; } }