Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
int comp (const void * elem1, const void * elem2)
{
int f = *((int*)elem1);
int s = *((int*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
#include<stdio.h>
void merge(int arr[], int left, int mid, int right){
int len1 = mid - left +1;
int len2 = right - mid;
int i;
int index1 = 0 , index2 = 0;
// create temp array
int left_array[len1];
void merge(int arr[], int left, int mid, int right){
int len1 = mid - left +1;
int len2 = right - mid;
int i;
int index1 = 0 , index2 = 0;
// create temp array
int left_array[len1];
int right_array[len2];
void merge_sort(int data[], int left , int right){
int mid;
if(left == right);
else {
mid = (left + right)/2;
merge_sort(data, left, mid);
merge_sort(data, mid+1, right)
#include<stdio.h>
int factorial(int n){
if(n==1)
return 1;
else
return n * factorial(n-1);
}
int main(){
#include<stdio.h>
int factorial(int n){
int i;
int answer=1;
for(i=n;i>=1;i--){
answer = answer*i;
}
@ming2540
ming2540 / selection.c
Created April 10, 2018 19:27
selection.c
#include<stdio.h>
void selection_sort(int data[], int data_number){
int i,j,temp;
int min_index;
for(i=0 ; i < data_number ; i++){//until done sorting
min_index = i;
for(j = i ; j < data_number ;j++)//check min value
#include<stdio.h>
void bubble_sort(int data[], int data_number){
int i,j,temp;
for(i=0 ; i < data_number ; i++)//until done sorting
for(j=0; j < data_number-1 ; j++) // for one time
if(data[j] > data[j+1]){
//swap data
temp = data[j];