Skip to content

Commit

Permalink
Merge pull request #54 from Ksunyy/main
Browse files Browse the repository at this point in the history
sort
  • Loading branch information
lordoz234 authored Nov 10, 2023
2 parents 832902a + 2504621 commit ca178d9
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions task3/Shvetssova.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>

void sort(int array[], int size) {
sort1(array, 0, size - 1);
}

void sort1(int array[], int first, int last)
{

int l = first;
int r = last;
int pivot = array[(first + last) / 2];
if (first > last)
return;

while (l <= r)
{
while (array[l] < pivot)
l++;
while (array[r] > pivot)
r--;
if (l <= r)
{
int smth = array[l];
array[l] = array[r];
array[r] = smth;
l++;
r--;
}
}
sort1(array, first, r);
sort1(array, l, last);
}

int main()
{
int n;
scanf("%d", &n);
int array[n];
for (int i = 0; i < n; i++)
{
scanf("%d", &array[i]);
}
sort(array, n);
for (int i = 0; i < n; i++)
{
printf("%d ", array[i]);
}
return 0;
}

0 comments on commit ca178d9

Please sign in to comment.