Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- void gnome_sort(int* arr, int length){
- int buf_1;
- for (int i = 0; i < length; i++){
- if (arr[i] > arr[i+1]){
- buf_1 = arr[i];
- arr[i] = arr[i+1];
- arr[i+1] = buf_1;
- if (i != 0){
- i-=2;
- }
- }
- }
- }
- int** alloc_matr(int rows, int length)
- {
- int i;
- int** matrix = (int**)calloc(rows, sizeof(int*));
- for(i=0;i<rows;i++)
- {
- matrix[i] = (int*)calloc(length, sizeof(int));
- }
- return matrix;
- }
- void output_matr(int** matrix, int rows, int length)
- {
- int i,j;
- for(i=0;i<rows;i++){
- for(j=0;j<length;j++){
- printf("%d ", matrix[i][j]);
- }
- printf("\n");
- }
- }
- int main(){
- int n = 5;
- int k = 5;
- int** matrix = alloc_matr(n,k);
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < k; j++){
- matrix[i][j] = rand() % 20;
- }
- }
- output_matr(matrix, n, k);
- for (int i = 0; i < n; i++){
- gnome_sort(matrix[i], k);
- }
- output_matr(matrix, n, k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement