Gnome sort(stupid sort) is a sorting algorithm which is similar to insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is conceptually simple, requiring no nested loops.
Below is the source code for C Program to Sort an Array using Gnome Sort which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C Program to Sort an Array using GnomeSort */
#include <stdio.h>
void main()
{
int i, temp, ar[10], n;
printf("\nenter the elemts number u would like to enter:");
scanf("%d", &n);
printf("\nenter the elements to be sorted through gnome sort:\n");
for (i = 0; i < n; i++)
scanf("%d", &ar[i]);
i = 0;
while (i < n)
{
if (i == 0 || ar[i - 1] <= ar[i])
i++;
else
{
temp = ar[i-1];
ar[i - 1] = ar[i];
ar[i] = temp;
i = i - 1;
}
}
for (i = 0;i < n;i++)
printf("%d\t", ar[i]);
}
Output :
/* C Program to Sort an Array using GnomeSort */
enter the elemts number u would like to enter:5
enter the elements to be sorted through gnomesort:
9
5
2
4
3
2 3 4 5 9
Above is the source code for C Program to Sort an Array using Gnome Sort which is successfully compiled and run on Windows System.The Output of the program is shown above .
Gnome sort(stupid sort) is a sorting algorithm which is similar to insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is conceptually simple, requiring no nested loops.
Below is the source code for C Program to Sort an Array using Gnome Sort which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
Output :
Above is the source code for C Program to Sort an Array using Gnome Sort which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer