#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)
{

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

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

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

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

Sign up to vote on this title
UsefulNot useful