Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
8. [7, 3, 5, 8, 2, 9, 4, 15, 6] dizisini aşağıda verilen algoritmaları kullanarak sıralayınız.
a. İnsertion Sort (araya sokma sıralaması),
b. Selection Sort (seçmeli sıralama),
c. Bubble Sort (kabarcık sıralama),
d. Merge Sort (Birleşmeli sıralama),
Hazırlayacağınız projede yukarıda bahsedilen algoritmaların her birini ayrı ayrı fonksiyon olarak yazınız.
*/
#include <iostream>
#include <cstdlib>
using namespace std;
void yazdir(int dizi[], int uzunluk)
{
int i;
for (i=0; i < uzunluk; i++)
cout << dizi[i] << " - ";
cout << "n";
}
//buble sort
void bubble_sort(int dizi[] , int dizi_uzunluk)
{
int i,j,gecici;
for(i=0; i< dizi_uzunluk; i++)
{
for(j=dizi_uzunluk-1; j>i; j--)
{
if(dizi[j-1] > dizi[j])
{
gecici = dizi[j-1];
dizi[j-1] = dizi[j];
dizi[j] = gecici;
}
}
}
}
//insertion sort
void insertion_sort(int dizi[], int dizi_uzunluk)
{
int i, j;
int gecici;
for(i=1; i < dizi_uzunluk; i++)
{
gecici = dizi[i];
j = i-1;
while (j >= 0 && dizi[j] > gecici)
{
dizi[j+1] = dizi[j];
j--;
}
dizi[j+1] = gecici;
}
}
//selection sort
void selection_sort(int dizi[] , int dizi_uzunluk)
{
int i,j,gecici;
for(i =0 ; i< dizi_uzunluk; i++)
{
for(j=i+1; j< dizi_uzunluk; j++)
{
if(dizi[j] < dizi[i])
{
gecici = dizi[i];
dizi[i] = dizi[j];
dizi[j] = gecici;
}
}
}
}
void merge(int dizi[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = dizi[l + i];
for (j = 0; j < n2; j++)
R[j] = dizi[m + 1+ j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
dizi[k] = L[i];
i++;
}
else
{
dizi[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
dizi[k] = L[i];
i++;
k++;
}
while (j < n2)
{
dizi[k] = R[j];
j++;
k++;
}
}
void merge_sort(int dizi[], int l, int r)
{
if (l < r)
{
int m = l+(r-l)/2;
merge_sort(dizi, l, m);
merge_sort(dizi, m+1, r);
merge(dizi, l, m, r);
}
}
int main() {
int dizi[] = {7, 3, 5, 8, 2, 9, 4, 15, 6};
int dizi_boyutu = sizeof(dizi)/sizeof(dizi[0]);
yazdir(dizi, dizi_boyutu);
bubble_sort(dizi, dizi_boyutu);
yazdir(dizi, dizi_boyutu);
int dizi1[] = {7, 3, 5, 8, 2, 9, 4, 15, 6};
yazdir(dizi1, dizi_boyutu);
selection_sort(dizi, dizi_boyutu);
yazdir(dizi, dizi_boyutu);
int dizi2[] = {7, 3, 5, 8, 2, 9, 4, 15, 6};
yazdir(dizi2, dizi_boyutu);
insertion_sort(dizi, dizi_boyutu);
yazdir(dizi, dizi_boyutu);
int dizi3[] = {7, 3, 5, 8, 2, 9, 4, 15, 6};
yazdir(dizi3, dizi_boyutu);
merge_sort(dizi3,0, dizi_boyutu-1);
yazdir(dizi3, dizi_boyutu);
return 0;
}
![]() |
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