Skip to content

Instantly share code, notes, and snippets.

View Pr3d4dor's full-sized avatar

Gianluca Bine Pr3d4dor

  • Brazil
View GitHub Profile
//Sequential search function in c
int seqSearch(int *vet,int n,int x){
int i;
for (i=0;i<n;i++){
if (x==vet[i])
return 1;
}
}
//Merge sort function in c
void mergeSort(int *vet,int *vetAux,int left,int right){
int middle;
if (left<right){
middle=(left+right)/2;
mergeSort(vet,vetAux,left,middle);
mergeSort(vet,vetAux,middle+1,right);
insert(vet,vetAux,left,middle+1,right);
}
}
//Insertion sort function in c
void insertionSort(int *vet,int n){
int i,j,temp;
for(i=1;i<n;i++){
temp=vet[i];
j=i-1;
while((j>=0)&&(vet[j]>temp)){
vet[j+1]=vet[j];
j--;
}
//Selection sort function in c
void selectionSort(int *vet,int n){
int i,j,min,aux;
for (i=0;i<n-2;i++){
min=i;
for (j=i+1;j<n;j++){
if (vet[j]<vet[min])
min=j;
}
aux=vet[i];
//Bubble sort function in c
void bubbleSort(int *vet,int n){
int i,j,aux;
for (i=0;i<n-1;i++){
for (j=0;j<n-i-1;j++){
if (vet[j]>vet[j+1]){
aux=vet[j];
vet[j]=vet[j+1];
vet[j+1]=aux;
}