Revert "Merge pull request #513 from tania-cmyk/master"

This reverts commit 5eebdedefc, reversing
changes made to 53e92ebc05.
This commit is contained in:
Krishna Vedala 2020-07-05 09:57:54 -04:00
parent 6072e3b111
commit 16110cd079
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
1 changed files with 13 additions and 9 deletions

View File

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