# How do shell sort algorithms work

## Sorting algorithms

### Principle:

The algorithm compare the series to two neighboring elements and
swaps themif they are in the wrong order are present.
This process will as long as repeated until no more exchanges are necessary. This usually requires several runs.

Depending on whether it is sorted in ascending or descending order, the larger or smaller elements rise like Blow in the water (hence the name) further and further up, that is, to the end of the row.

The BubbleSort algorithm is particularly suitable for presorted data series.

Example:

The numbers 5, 3, 6, 1 and 4 should be sorted in ascending order.

5 1st run 2nd run 3rd pass 4th pass The array is now sorted

### Structogram / syntax:

 n = number;do { swapped = false; for (i = 0; i i++)   { if (number [i + 1]     { //-----Exchange----- h = number [i]; number [i] = number [i + 1]; number [i + 1] = h; swapped = true;     }   } n--; }while (swapped == true);

Example: Sorting 50 numbers in ascending order in the number field [50]

 n = 50;do { swapped = false; for (i = 0; i i++)   { if (number [i + 1]     { //-----Exchange----- h = number [i]; number [i] = number [i + 1]; number [i + 1] = h; swapped = true;     }   } n--; }while (swapped == true);