This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int factorial(int n){ | |
if(n==1) | |
return 1; | |
else | |
return n * factorial(n-1); | |
} | |
int main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int factorial(int n){ | |
int i; | |
int answer=1; | |
for(i=n;i>=1;i--){ | |
answer = answer*i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; |