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
int gcd(int a, int b) | |
{ | |
while(b) b ^= a ^= b ^= a %= b; | |
return a; | |
} |
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
int linear_search(int *list,int size, int key) | |
{ | |
int i; | |
for(i=0;i<=size;++i) | |
{ | |
if(key==list[i]) | |
return i; | |
} | |
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
def fib_n n | |
i=0 | |
j=1 | |
(1..n).map{i=j+j=i} | |
i | |
end |
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
def prime? n | |
return true if n == 2 | |
return false if n < 2 or n % 2 == 0 | |
for d in (3..Math.sqrt(n).to_i).step(2) do | |
return false if n % d == 0 | |
end | |
return true | |
end |
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> | |
#include <sys/time.h> | |
void Multiply(int n, double** a, double** b, double** c) | |
{ | |
int i=0; | |
int j=0; | |
int k=0; | |
for(i = 0; i < n; 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
public class QuickSort | |
{ | |
private int[] a; | |
private int n; | |
public void sort(int[] b) | |
{ | |
this.a=b; | |
n=a.length; | |
qs(0, n-1); |
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
public class InsertionSort | |
{ | |
private static int[] a; | |
private static int n; | |
public static void sort(int[] b) | |
{ | |
a=b; | |
n=a.length; | |
isort(); |
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 isort (int array[], int len) | |
{ | |
register int i, j, t; | |
for (i = 1; i < len; i++) | |
{ | |
j = i; | |
t = array[j]; | |
while (j > 0 && array[j-1] > temp) | |
{ | |
array[j] = array[j-1]; |
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 bubblesort (int *array, int len) | |
{ | |
register int j, t=1; | |
while(len-- && swap) | |
{ | |
for (j=swap=0; j<len-1; j++) | |
{ | |
if (array[j]>aray[j+1]) | |
{ | |
swap=1; |
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
public class BubbleSort | |
{ | |
private static int[] a; | |
private static int n; | |
public static void sort(int[] b) | |
{ | |
a=b; | |
n=a.length; | |
bubblesort(); |
OlderNewer