Gnome Sort Intro: Gnome sort is similar to Insertion sort except, moving an element to its proper place is accomplished by a series of swaps, as in Bubble Sort. Gnome sort is also called as Stupid Sort. The person looks in the flower pot next to him and the previous one; if they are in the right order he steps one pot forward, or else he swaps them and steps one pot back. Boundary conditions: if there is no previous pot, he steps forwards; if there is no pot next to him, he is finished with his work.

Algorithm Code:

void gnomesort(int n, int ar[]) {              
     for (int i = 0; i < n; ) {                 
         if (i == 0 || ar[i-1] <= ar[i]) {      
             // Outer loop functionality --- scan to larger index  
 	} else {                               
 	    // Inner loop functionality --- move to smaller index 
 	    int tmp = ar[i]; ar[i] = ar[i-1]; ar[--i] = tmp;      

Pseudo Code Detailed:

procedure gnomeSort(a[]):
    pos := 0
    while pos < length(a):
        if (pos == 0 or a[pos] >= a[pos-1]):
            pos := pos + 1
            swap a[pos] and a[pos-1]
            pos := pos - 1