Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
1)Seçmeli Sıralama (Selection Sort)
________________________________________
int[] array={3,5,2,7,1,9};
int array2;
for (int k=0;k<array.length;k++){
int minIndex=k;
for (int i=k+1;i<array.length;i++){
if (array[i]<array[minIndex]){
minIndex=i;
}
}
array2= array[k];
array[k]=array[minIndex];
array[minIndex]=array2;
}
for (int i=0;i<array.length;i++){
System.out.println(array[i]+ " ");
}
---------------------------
2)Hızlı Sıralama(Quick Sort)
________________________________________
import java.util.Arrays;
public class QuickSort
{
public static void main(String[] args)
{
Integer[] array = new Integer[] { 12, 13, 24, 10, 3, 6, 90, 70 };
quickSort( array, 0, array.length - 1 );
System.out.println(Arrays.toString(array));
}
public static void quickSort(Integer[] arr, int dusuk, int yuksek)
{
if (dusuk >= yuksek){
return;
}
int middle = dusuk + (yuksek - dusuk) / 2;
int pivot = arr[middle];
int i = dusuk, j = yuksek;
while (i <= j)
{
while (arr[i] < pivot)
{
i++;
}
while (arr[j] > pivot) {
j--;
}
if (i <= j)
{
swap (arr, i, j);
i++;
j--;
}
}
if (dusuk < j){
quickSort(arr, dusuk, j);
}
if (yuksek > i){
quickSort(arr, i, yuksek);
}
}
public static void swap (Integer array[], int x, int y)
{
int temp = array[x];
array[x] = array[y];
array[y] = temp;
}
}
---------------------------
3)Eklemeli Sıralama (Insertion Sort)
________________________________________
public class Insertion {
public static void main(String [] args)
{
int[] nums = {31,1,56,33,777,123,25,15,17,20,11,10,1,23,3};
Insertion dz = new Insertion();
dz.Sort(nums);
dz.print(nums);
}
private void Sort(int[] nums){
int temp = 0;
int lenght = nums.length;
for(int i = 1; i < lenght; i++) // 1den başlayarak dizinin sonuna kadar devam et
{
if(nums[i] < nums[i-1]) // büyük ile küçüğü değiştir ve tekrar indis 1 e git.
{
temp = nums[i]; // dizide indisler arası değişiklik olacağından
nums[i] = nums[i-1]; // temp adında bir değişkene ihtiyaç duyarız.
nums[i-1] = temp;
i = 1;
}
}
}
private void print(int[] nums)
{
for(int i = 0; i < nums.length; i++)
{
System.out.print(nums[i] + " ");
}
}
}
----------------------------------
4)Bubble Sort (Baloncuk/Kabarcık Sıralama)
___________________________________________________
import java.util.Arrays;
public class BubleSort {
int[] a = {3,17,86,-9,7,-11,38} ;
public static void main(String[] args) {
BubleSort bbs = new BubleSort();
System.out.println("nSıralamadan önce:");
System.out.println(Arrays.toString(bbs.a));
Arrays.sort(bbs.a);
System.out.println("nnSıralamadan sonra:");
System.out.println(Arrays.toString(bbs.a));
}
}
----------------------------------
5)Counting Sort (Sayarak Sıralama)
_________________________________________
import java.util.Arrays;
import java.util.Arrays;
class CountingSort {
void countSort(int array[], int size) {
int[] output = new int[size + 1];
int max = array[0];
for (int i = 1; i < size; i++) {
if (array[i] > max)
max = array[i];
}
int[] count = new int[max + 1];
for (int i = 0; i < max; ++i) {
count[i] = 0;
}
for (int i = 0; i < size; i++) {
count[array[i]]++;
}
for (int i = 1; i <= max; i++) {
count[i] += count[i - 1];
}
for (int i = size - 1; i >= 0; i--) {
output[count[array[i]] - 1] = array[i];
count[array[i]]--;
}
for (int i = 0; i < size; i++) {
array[i] = output[i];
}
}
public static void main(String args[]) {
int[] data = { 4, 2, 2, 8, 3, 3, 1 };
int size = data.length;
CountingSort cs = new CountingSort();
cs.countSort(data, size);
System.out.println("Sıralanmış Hali: ");
System.out.println(Arrays.toString(data));
}
}
------------------------------------------
Seçmeli Sıralama (Selection Sort)
int[] arr={6,8,1,5,7,17};
int arr2;
for (int k=0;k<arr.length;k++){
int minIndex=k;
for (int i=k+1;i<arr.length;i++){
if (arr[i]<arr[minIndex]){
minIndex=i;
}
}
arr2= arr[k];
arr[k]=arr[minIndex];
arr[minIndex]=arr2;
}
for (int i=0;i<arr.length;i++){
System.out.println(arr[i]+ "Çıktı: ");
}
___________________________________________________________
![]() |
Notes is a web-based application for online 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 14 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