NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define A 10000
#define B 50000
#define C 100000

void mergesort(int arr[], int l, int m, int r){
int i, j, k;
//Sol ve sağ dizi için değişkenker
int n1 = m - l + 1;
int n2 = r - m;
//Geçici dizilerimiz, boyutları dizimizi ikiye böleceğimiz esasına göre oluşturuyoruz.
int L[n1], R[n2];
//Aşağıdaki iki döngü geçici dizilerimize elemanları atıyor.
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
//Yukarıda yaptığımız işlemlerden ötürü değişkenlerimizin sayıları değişti, burada fabrika ayarlarına döndürüyoruz.
i = 0;
j = 0;
k = l;
//Esas birleştirme mevzusu burada dönüyor.
//sol ve sağ dizide eleman oldukça döngümüz dönecek
while (i < n1 && j < n2){
//Eğer sol dizinin i. indisindeki eleman, sağ dizinin j. indisindeki elemandan küçük eşitse
//yeni oluşturulacak dizinin ilk elemanı sol dizinin ilk elemanı oluyor.
if (L[i] <= R[j]){
arr[k] = L[i];
i++;
}
//Yok değilse sağ dizinin ilk elemanı yeni dizimizin ilk elemanı oluyor.
else{
arr[k] = R[j];
j++;
}
//dikkat edin, k değişkenini her durumda artırıyoruz.
k++;
}
//Eğer atama işlemlerinden sonra sol dizide boşta eleman kaldıysa boşta kalan yerlere yerleştiriyoruz.
while (i < n1){
arr[k] = L[i];
i++;
k++;
}
//Eğer atama işlemlerinden sonra sağ dizide boşta eleman kaldıysa boşta kalan yerlere yerleştiriyoruz.
while (j < n2){
arr[k] = R[j];
j++;
k++;
}
}

float merge(int arr[], int l, int r){
//sol sağdan küçükse statement'a gider, bu şartı koymasaydık en küçük parçalara ayrılmasının kontrolünü yapamazdık..
clock_t ilk,son;
ilk=clock();
if (l < r){
//dizinin ortasını hesaplıyoruz.
int m = l+(r-l)/2;
merge(arr, l, m);
merge(arr, m+1, r);
//Esas fonksiyona dizimizi, sol indisi, orta indisi ve sağ indisi parametre olarak yolluyoruz
mergesort(arr, l, m, r);
}
son=clock();
return (float) (son-ilk);
}

void merge_rastgele(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=0;i<eleman_sayisi;i++){
dizi[i]=rand()%9;
}
printf("Merge Sort : Siralama %.0f milisaniye surdu.n",merge(dizi,0,eleman_sayisi));
}

void merge_sirali(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=0;i<eleman_sayisi;i++){
dizi[i]=i;
}
printf("Merge Sort : Siralama %.0f milisaniye surdu.n",merge(dizi,0,eleman_sayisi));
}

void merge_tersten_sirali(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=eleman_sayisi;i>0;i--){
dizi[i]=i;
}
printf("Merge Sort : Siralama %.0f milisaniye surdu.n",merge(dizi,0,eleman_sayisi));
}

int main(){
merge_rastgele(A);
merge_sirali(A);
merge_tersten_sirali(A);
return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define A 10000
#define B 50000
#define C 100000

void downheap( int dizi[], int k, int N) {
int T=dizi[k-1];
while ( k<=N/2) {
int j=k+k;
if( (j<N) && ( dizi[j-1]<dizi[j] ) ) j++;
if ( T>=dizi[j-1]) break;
else{
dizi[k-1]=dizi[j-1]; k= j;
}
}
dizi[k-1]=T;
}

float heap(int dizi[],int eleman_sayisi){
int x;
//en büyük elamanı bul en başa al
clock_t ilk,son;
ilk=clock();
for (int k=eleman_sayisi/2;k>0;k--)
downheap(&dizi[0],k,eleman_sayisi);
// küçükten büyüğe sıralama için
do{
x=dizi[0];
dizi[0]=dizi[eleman_sayisi-1];
dizi[eleman_sayisi-1]=x;
--eleman_sayisi;
downheap(&dizi[0], 1,eleman_sayisi); //en büyük elaman sona atılıyor
} while (eleman_sayisi>1);
son=clock();
return (float) (son-ilk);
}

void heap_rastgele(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=0;i<eleman_sayisi;i++){
dizi[i]=rand()%9;
}
printf("Heap Sort : Siralama %.0f milisaniye surdu.n",heap(dizi,eleman_sayisi));
}

void heap_sirali(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=0;i<eleman_sayisi;i++){
dizi[i]=i;
}
printf("Heap Sort : Siralama %.0f milisaniye surdu.n",heap(dizi,eleman_sayisi));
}

void heap_tersten_sirali(int eleman_sayisi){
int dizi[eleman_sayisi],i,j;
for(i=eleman_sayisi;i>0;i--){
dizi[i]=i;
}
printf("Heap Sort : Siralama %.0f milisaniye surdu.n",heap(dizi,eleman_sayisi));
}

int main(){
heap_rastgele(A);
heap_sirali(A);
heap_tersten_sirali(A);
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.