Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/hw_Optimal_Sort/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#include "sort.h"

int main()
{
int array[100];
int count = 0;

while (count < 100 && scanf("%d", &array[count]) == 1) {
count++;
}

int moved = sort_array(array, count);

return moved;
}
16 changes: 16 additions & 0 deletions src/hw_Optimal_Sort/sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
int sort_array(int* array, int count) {
int moved_count = 0;
// сортировка пузырьком
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
moved_count++;
}
}
}

return moved_count;
}