#ifdef _MSC_VER

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE
#endif
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
int v[20],n;
FILE *f;
void citire()
{
n=0;
f=fopen("pr.txt","rt");
do
{
fscanf (f,"%d",&v[n]);
n++;
}while (!feof(f));
fclose(f);
}
void afisare()
{
int i;
printf("\nSirul este: \n");
for (i=0;i<n;i++)
printf("%d\t", v[i]);
}
void selectie()
{
int i,j,aux,pozmin,min;
for(i = 0;i < n-1; i++)
{
pozmin=i;
min = v[i];
for(j= i+1; j < n; j++)
{
if(v[j] < min)
{min=v[j];
pozmin=j;
}
}
aux= v[i];
v[i]= min;
v[pozmin]= aux;
}
}
void selectie_performanta(void)
{

d=i-1. j=i-1. for(j=i+1.j. while(s<=d) { m=(s+d)/2. aux=v[pozmin]. s=0.j. for(i=0. while(j>=0 && v[j]>aux) { v[j+1]=v[j]. v[i]=aux. } } void insertie_binara(void) { int i.aux.i++) { pozmin=i.j. else s=m+1. if (v[m]>aux) d=m-1.i<n.m.j++) { if (v[j]<v[i]) { pozmin=j.i<n.i++) { aux=v[i].i++) { aux=v[i]. } } } } void insertie(void) { int i. j=j-1. j--) {v[j+1]=v[j]. j>=s. for (i=0.j<n.pozmin. v[pozmin]=v[i].s. int aux. } for(j=i-1.d.aux.i<n-1.int i.k. . for (i=0. } v[j+1]=aux.

k=n-1.b-1).b-1).j. j=d. return 0. } } st=k+1. } } while (s<d). v[d]=aux.aux.j.s-1.j<=dr. int b) { int i.j. } while(st<=dr). int aux. v[j-1]=v[j]. int d.} . } } dr=k-1. dr=n-1.j--) { if(v[j-1] >v[j]) { aux=v[j-1]. Radix_interschimbare(i. Radix_interschimbare(d+1. if ((d>s) && (b>=0)){ i=s.v[s]=aux. v[j-1]=v[j].dr. k=j. do { while ((((v[s] >> b) & 1)==0) && (s<=d)) s++. do { for(j=dr. st=1. } int Radix_interschimbare(int s. while (((v[d] >> b) & 1) && (s>=d)) d--.st. } } void shakersort() { int i. v[j]=aux. k=j.j++) { if(v[j-1]>v[j]) { aux=v[j-1].j>=st. v[s]=v[d]. v[j]=aux. .k. if (s<d) { aux=v[s]. for(j=st.

gata. i++. j=dr.} void shellsort() { int inj.j. do{ while(i<=dr && v[i]<v[m]){ i++. i <= DIM-inj. v[j]=aux. a[i+inj] = aux. aux. } } void quicksort(int st.j--. int dr) { int i.m.j). } }while(!gata).dr). gata = 0. i++) if( a[i] > a[i+inj]) { aux = a[i]. register int i. dr. .} } void main() { int st. while(inj > 1) { inj /= 2. int opt. //avansare in ambele directii } } while(i<=j). v[i]=v[j]. a[i] = a[i+inj].} if (i<=j) //parcurgerile nu s-au intersectat { aux=v[i]. i=st. m=(st+dr)/2. //sortare din stanga if (st<j){ quicksort(st. inj = DIM.} //sortare din dreapta if(dr>i){ quicksort(i.} while(j>=st && v[j]>v[m]){ j--.aux. for( i = 0. do { gata = 1.

case 4: selectie().Afisare Radix_interschimbare\n"). printf("6. } .Afisare!\n"). break. break. case 9: Radix_interschimbare(0. default: printf("Optiunea introdusa nu este valida!\n"). printf("9. break.n-1. &opt).Afisare quicksort\n"). } }while (opt!=0). case 2: afisare(). printf("7. printf("Optiunea dorita este? \n"). break.15). case 7: quicksort(0. printf("2. case 5:selectie_performanta().Iesire!\n"). printf("3.do { printf("\n-------Meniu-------\n"). break. break. printf("8.n-1). switch(opt) { case 1: citire(). case 8: shakersort(). case 0: break. break. scanf("%d". break. case 3: insertie(). case 6: insertie_binara(). break. _getch(). printf("4.Sortare prin selectie!\n"). printf("0. printf("5.Afisare prin selectie performanta\n").Afisare shakersort\n"). printf("1. Afisare prin insertie binara:\n").Citire fisier!\n").Sortare prin insertie!\n").

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.