Exemple #1
0
int main()
{
	ElementType a[] = {34, 8, 64, 51, 32, 21, 3};
	int i = 0;
	
	PRINT_INT_ARRAY(a, sizeof(a)/sizeof(a[0]), i);
	Heapsort(a, sizeof(a)/sizeof(a[0]));
	PRINT_INT_ARRAY(a, sizeof(a)/sizeof(a[0]), i);
	
	return 0;
}
Exemple #2
0
int main (int argc, char *argv[]) {
	int poradi, poradi_zpetne;
	int i;

	int * permutace;

	int digits = 0;
	int power_of_ten = 1;

	int permutace_len;
	int permutace_count;
	char * tail;

	if (argc == 1)
		permutace_len = 9;
	else if (argc == 2)
		permutace_len = (int) strtou32 (argv[1]);
	else {
		writes (stderr, "Pouziti: prec <delka permutace>\n");
        exit();
		return 1;
	}

	permutace_count = faktorial (permutace_len);

	/**
	 * Spocteme pocet cislic v desitkovem zapisu poctu permutaci,
	 * abychom mohli zarovnat vypis
	 */
	//while (permutace_count > power_of_ten) {
	//	power_of_ten *= 10;
	//	digits++;
	//}

	/**
	 * Test konzistence indexovani permutaci hrubou silou. 
	 *
	 * Projdeme vsechna poradi, dekodujeme permutaci, vytiskneme permutaci,
	 * permutaci zpet zakodujeme na poradi a porovname toto poradi
	 * s puvodnim. Jestli se lisi, tiskneme na konci radku "!!!FAIL!!!",
	 * jestli ne, tak "OK".
	 */
    permutace = (int *) 0x90000000;
	for (poradi = 1; poradi <= permutace_count; poradi++) {
		writes (stderr, "Permutace ");
        writei (stderr, poradi);
		writes (stderr, ": ");

  	    poradi_na_permutace (poradi, permutace, permutace_len);
		PRINT_INT_ARRAY (permutace, permutace_len, i);

		poradi_zpetne = permutace_na_poradi (permutace, permutace_len);
		if (poradi_zpetne == poradi)
			writes (stderr, " OK");
		else {
			writes (stderr, " FAILED, permutace_na_poradi vratila ");
            writei (stderr, poradi_zpetne);
        }
		writes (stderr, "\n");
	}
	
    exit();
	return 0;
}
Exemple #3
0
int main(){
	int array[] = {0,4,55,2,5,4,0,55,2,55,123,123,123,4,4,2,2,2,2,2};
	CountingSort(array, sizeof(array)/sizeof(int), 123);
	PRINT_INT_ARRAY(array, sizeof(array)/sizeof(int));
	return 0;
}