Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort #54

Merged
merged 12 commits into from
Nov 10, 2023
Merged

sort #54

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
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;
}