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
// Function to sort an array a[] of size 'n' | |
void insertionSort(int a[], int n) | |
{ | |
int i, loc, j, k, selected; | |
for (i = 1; i < n; ++i) | |
{ | |
j = i - 1; | |
selected = a[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 <bits/stdc++.h> | |
using namespace std; | |
bool b[18]; | |
int n; | |
void get(int a,int n) | |
{ | |
for ( int i= 0; i < n; i ++) | |
{ | |
if (a%2==0) b[i]=false; | |
else b[i]=true; |
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
//Array in a spiral | |
int main() | |
{ | |
int i,j,n,w=3,l=0; // w и l - позволяют ориентироваться внутри массива | |
//w - отступ до дальней стенки, l - отступ от ближней | |
int a[4][4]={5,3,2,7,1,8,4,3,2,6,9,7,5,6,3,2}; //Массив 4 на 4 | |
i=0; | |
j=0; | |
for (n=0;n<16;++n) //Повторяется *кол-во элементов* раз |
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
//matrix_multiplication | |
int main() | |
{ | |
int a, b, c, d; | |
// Entering the matrices dimensions | |
do | |
{ | |
cout << "M1 dimensions: "; |
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
// Quicksort | |
template <typename T> | |
void quicksort(T arr, int l, int r) | |
{ | |
int i, j; | |
i = l; | |
j = r; | |
int middle = arr[(i + j) / 2]; | |
do |
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
// Insertion sort | |
for (int i = 0; i < N; i++) | |
{ | |
int j = i; | |
while (j > 0 && array[j] < array[j-1]) | |
{ | |
// Swap array[j] and array[j-1] | |
swap(array[j], array[j-1]); | |
j--; | |
} |
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
// Bubble sort | |
for (int i = 0; i < N; i++) | |
{ | |
for (int j = 0; j < N - i; j++) | |
{ | |
if (array[j] > array[j + 1]) | |
{ | |
swap(array[j+1], array[j]); | |
} | |
} |
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
//GCD_LCM | |
int a1 = a, | |
b1 = b; | |
while (b1 != 0) | |
{ | |
a1 %= b1; | |
swap(a1, b1); | |
} | |