1 / 10

SORTAREA TABLOURILOR UNIDIMENSIONALE PRIN METODA SELECTIEI DIRECTE -SELECT SORT-

SORTAREA TABLOURILOR UNIDIMENSIONALE PRIN METODA SELECTIEI DIRECTE -SELECT SORT-. Prof. Sofroni Iulia. DESCRIEREA METODEI.

chenoa
Télécharger la présentation

SORTAREA TABLOURILOR UNIDIMENSIONALE PRIN METODA SELECTIEI DIRECTE -SELECT SORT-

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SORTAREA TABLOURILOR UNIDIMENSIONALE PRIN METODA SELECTIEI DIRECTE-SELECT SORT- Prof. Sofroni Iulia

  2. DESCRIEREA METODEI Prin această metodă se aduce pe prima pozitie elementul cu valoarea cea mai mica din cele n elemente, apoi pe pozitia a 2-aelementul cu cea mai mica valoare din ultimele n-1, pe pozitia 3 elementul cel mai mic din ultimele n-2 s.a.m.d pana se ajunge la finalul vectorului.

  3. ENUNŢUL PROBLEMEI: Se dă un tablou a cu n elemente întregi. Să se realizeze sortarea crescătoare a elementelor tabloului.

  4. FIE TABLOUL UNIDIMENSIONAL A CE ARE URMĂTORUL CONŢINUT: 1 2 3 4 5 7 8 10 25 5 a:

  5. FIE TABLOUL UNIDIMENSIONAL A CE ARE URMĂTORUL CONŢINUT: 1 2 3 4 5 5 8 10 25 7 a:

  6. FIE TABLOUL UNIDIMENSIONAL A CE ARE URMĂTORUL CONŢINUT: 1 2 3 4 5 5 7 10 25 8 a:

  7. FIE TABLOUL UNIDIMENSIONAL A CE ARE URMĂTORUL CONŢINUT: 1 2 3 4 5 5 7 8 25 10 a:

  8. VARIABILE NECESARE • a – tabloul unidimensional; • n – lungimea tabloului; • aux – pentru interschimbul elementelor (de acelaşi tip cu elementele tabloului); • i – contor pe care se aduce valoarea minima din ultimele n-i-1; • j – contor pentru parcurgerea ultimelor n-i-1 elemente pentru identificarea minimului; se initializeaza cu i+1

  9. ALGORITMUL for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(a[i]>a[j]) { aux =a[i]; a[i] =a[j]; a[j]=aux; }

  10. Aplicatia 1 • Sa se scrie un program care citeste un vector, il afiseaza, sorteaza descrescator elementele acestuia si apoi il reafiseaza sortat.

More Related