Skip to content

Instantly share code, notes, and snippets.

View afishr's full-sized avatar
👁️

Alex Calugari afishr

👁️
View GitHub Profile
// 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];
#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;
//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) //Повторяется *кол-во элементов* раз
@afishr
afishr / matrix.cpp
Last active October 31, 2018 06:45
//matrix_multiplication
int main()
{
int a, b, c, d;
// Entering the matrices dimensions
do
{
cout << "M1 dimensions: ";
// 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
// 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--;
}
// 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]);
}
}
@afishr
afishr / GCD_LCM.c
Last active September 17, 2018 05:58
//GCD_LCM
int a1 = a,
b1 = b;
while (b1 != 0)
{
a1 %= b1;
swap(a1, b1);
}