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
    
  
  
    
  | #include <stdio.h> | |
| int main() | |
| { | |
| int n1, n2, i, gcd; | |
| printf("Enter two integers: "); | |
| scanf("%d %d", &n1, &n2); | |
| for(i=1; i <= n1 && i <= n2; ++i) | |
| { | |
| // Checks if i is factor of both integers | |
| if(n1%i==0 && n2%i==0) | 
  
    
      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 main() { | |
| print(hornerRule([1, 3, 2, 1], 2)); | |
| } | |
| hornerRule(List<int> list, int x) { | |
| int result = list[0]; | |
| int n = list.length; | |
| for (int i = 1; i < n; i++) { | |
| result = result * x + list[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
    
  
  
    
  | main(){ | |
| inversion(); | |
| } | |
| inversion(){ | |
| List<int> list = [2,3,8,6,1]; | |
| for(int i = 0; i < list.length;i++){ | |
| for(int j = i+1; j<list.length;j++){ | |
| if(i<j&& list[i]>list[j]){ | |
| print("pair {$i,$j} is an inversion"); | |
| print("${list[i]} and ${list[j]} is an inversion"); | 
  
    
      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
    
  
  
    
  | main() { | |
| print(bubbleSort([8, 4, 6, 5])); | |
| } | |
| List<int> bubbleSort(List<int> list) { | |
| for (int j = 1; j < list.length; j++) { | |
| int x = 0; | |
| for (int i = 0; i < list.length - j; i++) { | |
| if (list[i] > list[i + 1]) { | |
| int key = list[i + 1]; | 
  
    
      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
    
  
  
    
  | main() { | |
| print(selectionSort([8, 18, 11, 44, 11, 11, 345, 222, 864, 44])); | |
| } | |
| List<int> selectionSort(List<int> list) { | |
| for (int j = 0; j < list.length - 1; j++) { | |
| int min = j; | |
| for (int i = j + 1; i < list.length; i++) { | |
| if (list[i] < list[j]) { | |
| min = 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
    
  
  
    
  | main(){ | |
| print(mergeSort([2,5,4,8,9])); | |
| } | |
| List<int> mergeSort(List<int> list){ | |
| int n = list.length; | |
| if(n<2){ | |
| return list; | |
| } | |
| int midIndexOfList = (n/2).floor(); | |
| List<int> leftList = new List(midIndexOfList); | 
  
    
      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
    
  
  
    
  | main() { | |
| print(insertionSort([8,9, 4, 2],3)); | |
| } | |
| bool insertionSort(List<int> list,int value) { | |
| for (int i = 0; i < list.length; i++) { | |
| if(value==list[i]){ | |
| return true; | |
| } | |
| } | |
| return false; | 
  
    
      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
    
  
  
    
  | main() { | |
| print(insertionSort([8,9, 4, 2, 6,10,12])); | |
| } | |
| List<int> insertionSort(List<int> list) { | |
| for (int j = 1; j < list.length; j++) { | |
| int key = list[j]; | |
| int i = j - 1; | 
NewerOlder