Skip to content

Instantly share code, notes, and snippets.

@eroltutumlu
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save eroltutumlu/d38f8c07440fa5ac3524 to your computer and use it in GitHub Desktop.

Select an option

Save eroltutumlu/d38f8c07440fa5ac3524 to your computer and use it in GitHub Desktop.
Sıralama Algoritmaları
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int loopIndex;
int loopIndex2;
void ShowSort(int,int[]);
void BubbleSort(int, int[]);
void InsertionSort(int,int *);
void SelectionSort(int,int *);
void QuickSort(int,int *);
int main(void) {
int *MyArrayList;
int SIZE;
int opt=0;
char Text[4];
MyArrayList= (int*)malloc(sizeof(int)*SIZE);
if(MyArrayList==NULL)
{
puts("Error");
}
while(1)
{
printf("Data Size: ");
scanf("%d",&SIZE);
for(loopIndex=0;loopIndex<SIZE;++loopIndex)
{
printf("%d. data ",loopIndex+1);
scanf("%d",&MyArrayList[loopIndex]);
}
printf("\n1-Bubble Sort\n2-InsertionSort\n3-SelectionSort\n4-QuickSort\n\n");
printf("Your option: ");
scanf("%d",&opt);
switch(opt)
{
case 1:
BubbleSort(SIZE,MyArrayList);
break;
case 2:
InsertionSort(SIZE,MyArrayList);
break;
case 3:
SelectionSort(SIZE,MyArrayList);
break;
case 4:
QuickSort(SIZE,MyArrayList);
break;
}
free(MyArrayList);
printf("Cikis icin quit yazmaniz yeterli: ");
scanf("%s",Text);
if(strncmp(Text,"quit",4)==0)
{
opt=5;
break;
}
}
if(opt==5)
printf("Good-Bye");
return 0;
}
void ShowSort(int SIZE,int Arr[])
{
for(loopIndex=0;loopIndex<SIZE;++loopIndex)
{
printf("%d\n",Arr[loopIndex]);
}
}
void BubbleSort(int SIZE, int *ArrayList)
{
int temp;
for(loopIndex=0;loopIndex<SIZE;++loopIndex)
{
for(loopIndex2=0;loopIndex2<SIZE-1;++loopIndex2)
{
if(*(ArrayList+loopIndex2)>*(ArrayList+loopIndex2+1))
{
temp=*(ArrayList+loopIndex2);
*(ArrayList+loopIndex2)=*(ArrayList+loopIndex2+1);
*(ArrayList+loopIndex2+1)=temp;
}
}
}
ShowSort(SIZE,ArrayList);
}
void InsertionSort(int SIZE,int *ArrayList)
{
int newNumber;
for(loopIndex=1;loopIndex<SIZE;++loopIndex)
{
newNumber=*(ArrayList+loopIndex);
for(loopIndex2=loopIndex-1;loopIndex2>=0 && newNumber<=*(ArrayList+loopIndex2);--loopIndex2)
{
*(ArrayList+loopIndex2+1)=*(ArrayList+loopIndex2);
}
*(ArrayList+loopIndex2+1)=newNumber;
}
ShowSort(SIZE,ArrayList);
}
void SelectionSort(int SIZE,int *ArrayList)
{
int index,TheSmallest;
for(loopIndex=0;loopIndex<SIZE-1;++loopIndex)
{
TheSmallest=*(ArrayList+SIZE-1);
index=SIZE-1;
for(loopIndex2=loopIndex;loopIndex2<SIZE-1;++loopIndex2)
{
if(*(ArrayList+loopIndex2)<TheSmallest)
{
TheSmallest=*(ArrayList+loopIndex2);
index=loopIndex2;
}
}
*(ArrayList+index)=*(ArrayList+loopIndex);
*(ArrayList+loopIndex)=TheSmallest;
}
ShowSort(SIZE,ArrayList);
}
void QuickSort(int SIZE,int *ArrayList)
{
printf("\nMantigini bilsen yeter.\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment