Question: Problem: Gnome Sort After getting to know your roommate better, you've discovered a rather strange secret about her family: they own the largest collections of

Problem: Gnome Sort

After getting to know your roommate better, you've discovered a rather strange secret about her family: they own the largest collections of gnomes in North America!!! The reason this came up is that recently some neighborhood hoodlums moved around all the gnomes in your roommates' parents' yard. Her parents desperately want to get the gnomes back into their proper numerical order. Luckily, you just learned about sorting in your programming course and your roommate has decided that it's only fitting that you write a program implementing Gnome sort to help her!

She kindly pointed you to the wiki page on Gnome sort:

https://en.wikipedia.org/wiki/Gnome_sort

Complete the function below so that it performs a Gnome sort on the input array of integers. The function prototype is given to you below and you can download the program to add your function to:

// Pre-condition: n is the size of the array gnomes.

// Post-condition: gnomes will be sorted in numerical order, from

// smallest to largest.

void gnomeSort(int gnomes[], int n);

The given code scaffold will contain all necessary testing code.

(Here is the code)

gnomesort-scaffold.c

#include  #define SIZE 5 #define MAXVAL 100 #define PRINT 1 void swap(int* ptrA, int*ptrB); void print(int array[], int length); void fillRandomArray(int array[], int length, int max); void gnomeSort(int array[], int length); int isSorted(int array[], int length); int main() { // Fill, print, and sort. srand(time(0)); int a[SIZE]; fillRandomArray(a, SIZE, MAXVAL); if (PRINT) print(a, SIZE); GnomeSort(a, SIZE); if (PRINT) print(a, SIZE); // Print out the final result. if (isSorted(a, SIZE)) printf("The sort worked properly. "); else printf("There was a problem with the sort. "); return 0; } // Prints out values in array[0]...array[length-1]. void print(int array[], int length) { int i; for (i=0; i array[i+1]) return 0; return 1; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!