Mesh Generation

2.4: Sorting and Searching

2.4 Sorting and Searching

Numerous methods may be used to sort an array containing items on which an ordering is defined.

Sorting by Comparison Algorithms

Sorting by insertion. Let us consider an array of size n and let us assume, at the stage i of the processing, for i = 1, , n ? 1, that the sub-array i (between the indices 1 and i) has already been sorted. The algorithm of sorting by insertion consists of inserting v = Tab( i + 1) in the sub-array i in the right place, by moving the items greater than v towards the right. This can be written as follows:

Algorithm 2.5

Sorting by insertion from the smallest to the largest.

    <b class="bold">Procedure InsertionSort (Tab)</b>    <b class="bold">FOR</b> i = 2, n       value <span class="unicode">?</span> Tab(i)       j <span class="unicode">?</span> i - 1       <b class="bold">WHILE</b> j > 0 <b class="bold">AND</b> TAB(j) > key          TAB(j + 1) <span class="unicode">?</span> TAB(j)          j <span class="unicode">?</span> j - 1       <b class="bold">END WHILE</b>       TAB(j + 1) <span class="unicode">?</span> value    <b class="bold">END FOR</b>

to obtain a sorting algorithm...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: DC-DC Converter Chips
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.