This file contains hidden or 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
| //find number of inversions in a list | |
| //inversion: number of (i,j) pairs where a[i] > a[j] and i < j | |
| int merge(int* a, int n); | |
| int countInversion(int* a, int n); | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <string.h> |
This file contains hidden or 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* a, int n); | |
| void mergeSort(int* a, int n); | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| #define NUM_ELEMENTS_IN(t) (sizeof(t)/sizeof(*t)) | |
| int main(int argc, char const *argv[]) |
This file contains hidden or 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 swap(int *a,int*b){ | |
| int t = *a; | |
| *a = *b; | |
| *b = t; | |
| } | |
| void selectionSort(int* a,int n){ | |
| int min; | |
| int i,k; | |
| for (i = 0; i < n-1; ++i) |
This file contains hidden or 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
| printf("hello world"); |
This file contains hidden or 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
| //random number generation | |
| srand(time(NULL)); | |
| printf("%d\n", rand()); |
This file contains hidden or 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
| #define MAX(a,b) ((a) > (b) ? ( a ) : ( b )) |
This file contains hidden or 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
| //copy n integer | |
| //string.h | |
| memcpy(dest,from,sizeof(int)*n); | |
| //memory management | |
| //stdlib.h | |
| void f(){ | |
| int* numberList = (int*) malloc(sizeof(int) * 1000); | |
| numberList = (int*)realloc(numberList,100); |
This file contains hidden or 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
| { | |
| "cmd": ["perl", "-w", "$file"], | |
| "file_regex": ".* at (.*) line ([0-9]*)", | |
| "selector": "source.perl" | |
| } |
This file contains hidden or 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
| //----Functions---- | |
| //arguments usage | |
| function min(){ | |
| var min = Number.POSITIVE_INFINITY; | |
| for( var i = 0; i < arguments.length; i++){ | |
| if( arguments[i] < min ){ | |
| min = arguments[i]; | |
| } | |
| } |