23.11.2006, 03:11
общий
это ответ
Здравствуйте, POSTAL!
Вот текст с использование сортировки методом выбора
Приложение:
// matrix_sort.cpp : Defines the entry point for the console application.//#include <stdlib.h>#include <stdio.h>#include <time.h>#define ASC 1#define DESC 2#define SIZE 10int A[SIZE][SIZE];void select_sort(int col, int order) { int i,j, index, temp; for(i=0; i<SIZE-1; i++) { index = i; for(j=i+1; j<SIZE; j++) { if(order == ASC) { if(A[index][col] < A[j][col]) index = j; } else { if(A[index][col] > A[j][col]) index = j; } } if(i!=index) { temp = A[i][col]; A[i][col] = A[index][col]; A[index][col] = temp; } }}int main(int argc, char* argv[]) { int i, j; srand((unsigned)time(NULL)); for(i=0; i<SIZE; i++) for(j=0; j<SIZE; j++) A[i][j] = rand()%100; for(i=0; i<SIZE; i++) { for(j=0; j<SIZE; j++) { printf("%d ", A[i][j]); } printf("\n"); } printf("\n"); for(i=0; i<SIZE; i++) if(i%2) select_sort(i, ASC); else select_sort(i, DESC); for(i=0; i<SIZE; i++) { for(j=0; j<SIZE; j++) { printf("%d ", A[i][j]); } printf("\n"); } return 0;}