Пример #1
0
/*
*  Does diagonal checking. 3 cases:
*  - the position is in the middle of the board
*  - the position lies in the descending diagonal line (from left to right)
*  - the position lies in the ascending diagonal line (from left to right)
*/
int 
checkDiagonal(int **board, int player, int row, int col, int board_size) 
{

	// middle position, need to check ascending and descending
	// the row is always equal to column
	// also row + column is equal to boardsize - 1
	if (row == col && row+col == board_size-1) {
		if (checkAscending(board, player, board_size) && checkDescending(board, player, board_size)) 
			return 1;
	}

	// descending diagonal line
	// the row is always equal to column in descending diagonal line
	// but row + column is not equal to boardsize - 1
	else if (row == col && row+col != board_size-1) {
		if (checkDescending(board, player, board_size))
			return 1;
	}

	// ascending diagonal line
	// the row is not equal to column in ascending diagonal line
	// but row + column is always equal to boardsize - 1
	else if (row != col && row+col == board_size-1) {
		if (checkAscending(board, player, board_size))
			return 1;
	}

	return 0;
}
Пример #2
0
void main()
{
    int numbers[10000];
    int size = rand()%1000 + 200;
    randomIntArray(numbers, size, 0, 10000);
    printArray(numbers, size);
    checkAscending(numbers, size);
    printf("After sorting:\n***********************\n");
    heapSort(numbers, size);
    printArray(numbers, size);
    checkAscending(numbers, size);
}
Пример #3
0
void main()
{
    int numbers[SIZE];
    randomIntArray(numbers, SIZE, 0, MAX);
    printArray(numbers, SIZE);
    checkAscending(numbers, SIZE);
    printf("After sorting:\n***********************\n");
    insertionSort0(numbers, SIZE);
    printArray(numbers, SIZE);
    checkAscending(numbers, SIZE);
    
}