Sort

Páginas: 2 (258 palabras) Publicado: 18 de diciembre de 2012
Sorting
• Sorting and searching are among the most common programming processes. • − − − We want to keep information in a sensible order. alphabetical orderascending/descending order order according to names, ids, years, departments etc.

Selection Sort
ð The list is divided into two sublists, sorted and unsorted,which are divided by an imaginary wall. ð We find the smallest element from the unsorted sublist and swap it with the element at the beginning of the unsorted data. ðAfter each selection and swapping, the imaginary wall between the two sublists move one element ahead, increasing the number of sorted elements and decreasing thenumber of unsorted ones. ð Each time we move one element from the unsorted sublist to the sorted sublist, we say that we have completed a sort pass. ð A list of nelements requires n-1 passes to completely rearrange the data.

• The aim of sorting algorithms is to put unordered information in an ordered form. • There aremany sorting algorithms, such as: − Selection Sort − Bubble Sort − Insertion Sort − Merge Sort − Quick Sort • The first three are the foundations for faster andmore efficient algorithms.

1

2

Selection Sort Example
Sorted Unsorted

Selection Sort Algorithm
/* Sorts by selecting smallest element in unsortedportion of array and exchanging it with element at the beginning of the unsorted list. Pre list must contain at least one item last contains index to last element inlist Post list is rearranged smallest to largest */ void selectionSort(int list[], int last) { int current, walker, smallest, tempData; for (current = 0; current
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Sense sortida
  • Sort stories
  • radix sort
  • Counting Sort
  • sense sortida
  • radix sort
  • Merge Sort
  • TURISMO EN SORTE

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS