Skip to content

Instantly share code, notes, and snippets.

@omeroot
Last active October 20, 2015 13:33
Show Gist options
  • Save omeroot/7562f372944f4df715a2 to your computer and use it in GitHub Desktop.
Save omeroot/7562f372944f4df715a2 to your computer and use it in GitHub Desktop.
//
// main.c
// sort
//
// Created by Markakod Development on 20/10/15.
// Copyright (c) 2015 Markakod Development. All rights reserved.
//
#include <stdio.h>
void WTFSorting(int[], int);
void arr_swap(int[],int,int);
int size(int[]);
void WTFSorting(int *arr, int size) {
printf("size: %d\n",size);
int res[size];
res[0] = arr[0];
for(int i = 1 ; i< size ; i++){
res[i] = arr[i];
for(int j = 0 ; j < (sizeof(res) / sizeof(res[0]))-1 ; j++){
if(arr[i] < res[j]){
arr_swap(&res[0],i,j);
}
}
}
for(int i = 0 ; i< size ; i++){
printf("%d ",res[i]);
}
printf("\n");
}
void arr_swap(int* array,int index1,int index2){
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
int main(){
int val[5] = { 64, 32, 85, 24, 13 };
int size = sizeof(val) / sizeof(val[0]);
WTFSorting(&(val[0]), size);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment