Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Rjesenje Pristupnog Zadatka Br 44

Rjesenje Pristupnog Zadatka Br 44

Ratings: (0)|Views: 9|Likes:
Published by Edin Priganica

More info:

Published by: Edin Priganica on Jul 02, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

11/04/2014

pdf

text

original

 
/* JU Univerzitet u TuzliFakultet Elektrotehnike Tehnicka informatikaEdin PriganicaGrupa: 2BIndeks: II-31/03Zadatak 44: Generisati slučajno određeni broj znakova. Uporediti a posteriorivremena potrebna zasortiranje Shell sortom i mergesortom.Program za uporedjivanje a posteriori vremena potrebnog zasortiranje Shell sortom i merge sortom.Resources: www.planet-source-code.comCopyright Edin Priganica 2004.*/#include<stdio.h>#include<stdlib.h>#include<time.h>#include<conio.h>#defineMAX15voidgetNumbers(int*);// Funkcija koja generise slucajne brojeve voidshellSort(int*);// Funkcija za Shell sortiranje voidmerge(int,int,int);// Funkcija za merge razdvajanje voidmergeSort(int,int);// Funkcija za Merge sortiranje intniz2[MAX];// Globalna variabla niza brojeva potrebna za Merge sort/**************** Main Funkcija ****************/intmain(void) {inti;intniz[MAX];clock_t start, finish;doubleduration1, duration2;getNumbers(niz);// Generisemo niz ascii kodovafor(i=0; i<MAX; i++)// Kopiramo niz ascii kodovaniz2[i]=niz[i];start=clock();// Pocinjemo mjeriti vrijeme Shell sortashellSort(niz);// Izvrsavamo Shell sortfinish=clock();// Zavrsavamo mjerenje vremena Shell sorta// Racunamovrijemeduration1 = 1000*(double)(finish - start) / CLOCKS_PER_SEC; 
 
start=clock();// Pocinjemo mjeriti vrijeme Merge sortamergeSort(0, MAX-1);// Izvrsavamo Merge sortfinish=clock();// Zavrsavamo mjerenje vremena Merge sorta// Racunamovrijemeduration2 = 1000*(double)(finish - start) / CLOCKS_PER_SEC;// Ispis sortiranog niza znakova Shell sortomprintf ("\nShellSort:\n");for(i=0; i<MAX; i++){printf ("%c ", (char)niz[i]); }printf ("\t\tTrajanje: %2.1f ms\n", duration1);getchar();// Pauza :)// Ispis sortiranog niza znakova Merge sortomprintf ("\nMergeSort:\n");for(i=0; i<MAX; i++){printf ("%c ", (char)niz2[i]);}printf ("\t\tTrajanje: %2.1f ms\n", duration2);getchar();// Pauza :)// Kraj main funkcijereturn0;}/**************** Ostale Funkcije ****************/// Get NumbersvoidgetNumbers(int*niz) {inti;inttmp;srand(time(NULL)); for(i=0; i<MAX; i++){tmp=rand();niz[i]=(tmp%25)+97;printf ("%c ", (char)niz[i]); }printf ("\n");}// Shell sortvoidshellSort(int*niz) {inth;inti, j, r;for( h = MAX/9; h > 0; h /= 3)
 
{for( i = h; i < MAX; i++){r = niz[i];for(j = i; j >=h; j = j-h){i( r < niz[j-h])niz[j] = niz[j-h];elsebreak;}niz[j] = r;}}}// Merge razdvajanjevoidmerge(intlow,intmid,inthigh) {inth,i,j,b[MAX],k;h=low;i=low; j=mid+1;while((h<=mid)&&(j<=high)){if (niz2[h]<=niz2[j]){b[i]=niz2[h];h++;}else{b[i]=niz2[j]; j++;}i++;}if (h>mid){for(k=j;k<=high;k++){b[i]=niz2[k];i++;}}else{for(k=h;k<=mid;k++){b[i]=niz2[k];i++;}}for(k=low;k<=high;k++) niz2[k]=b[k];}// Merge sortvoidmergeSort(intlow,inthigh)

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->