mirror of https://github.com/TheAlgorithms/C
Revert "Merge pull request #513 from tania-cmyk/master"
This reverts commit5eebdedefc
, reversing changes made to53e92ebc05
.
This commit is contained in:
parent
6072e3b111
commit
16110cd079
|
@ -6,16 +6,17 @@ void sort(int *numbers, int size)
|
|||
int pos = 0;
|
||||
while (pos < size)
|
||||
{
|
||||
if (pos == 0)
|
||||
pos = 1;
|
||||
if (numbers[pos] >= numbers[pos - 1] || pos == 0)
|
||||
if (numbers[pos] >= numbers[pos-1])
|
||||
pos++;
|
||||
else
|
||||
else
|
||||
{
|
||||
int tmp = numbers[pos - 1];
|
||||
numbers[pos - 1] = numbers[pos];
|
||||
int tmp = numbers[pos-1];
|
||||
numbers[pos-1] = numbers[pos];
|
||||
numbers[pos] = tmp;
|
||||
pos--;
|
||||
|
||||
if (pos == 0)
|
||||
pos = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +24,8 @@ void sort(int *numbers, int size)
|
|||
void display(int *array, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) printf("%d ", array[i]);
|
||||
for (i = 0; i < n; ++i)
|
||||
printf("%d ", array[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
@ -31,9 +33,10 @@ int main()
|
|||
{
|
||||
int size = 6;
|
||||
int i;
|
||||
int *numbers = malloc(size * sizeof(int));
|
||||
int *numbers = malloc(size*sizeof(int));
|
||||
printf("Insert %d unsorted numbers: \n", size);
|
||||
for (i = 0; i < size; ++i) scanf("%d", &numbers[i]);
|
||||
for (i = 0; i < size; ++i)
|
||||
scanf("%d", &numbers[i]);
|
||||
printf("Initial array: ");
|
||||
display(numbers, size);
|
||||
sort(numbers, size);
|
||||
|
@ -42,3 +45,4 @@ int main()
|
|||
free(numbers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue