Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "sort.h"
- #define SUCCESS 0
- int sort(int *a, int *N)
- {
- int tmp;
- int min = a[0];
- int max = a[0];
- int indmax;
- int indmin;
- for (int i = 0; i < *N; i++)
- {
- if (a[i] <= min)
- {
- min = a[i];
- indmin = i;
- }
- if (a[i] >= max)
- {
- max = a[i];
- indmax = i;
- }
- }
- if (indmin > indmax)
- {
- tmp = indmin;
- indmin = indmax;
- indmax = tmp;
- }
- for (int i = indmin; i < indmax; i++)
- {
- //printf("i = %d\n", i);
- for (int j = indmin; j < indmax + indmin - i - 1; j++)
- {
- //printf("j = %d\n", j);
- if (a[j] > a[j+1])
- {
- tmp = a[j];
- a[j] = a[j+1];
- a[j+1] = tmp;
- }
- }
- }
- return SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement