Skip to content

Instantly share code, notes, and snippets.

@sunmeat
sunmeat / horse.cpp
Last active April 29, 2025 17:43
horse moving C++
#include <iostream>
#include <windows.h>
using namespace std;
const int k = 5; // chess board size
int ar[k][k];
const int shift_count = 8;
@sunmeat
sunmeat / towers.cpp
Last active April 29, 2025 17:56
hanoj towers example C++
#include <iostream>
#include <windows.h>
using namespace std;
const int quantity = 5;
int sterjen1[quantity]{}, sterjen2[quantity]{}, sterjen3[quantity]{};
void moveDisc(int from[], int to[])
{
@sunmeat
sunmeat / 8queens.cpp
Last active April 29, 2025 18:01
8 queens C++
#include <conio.h>
#include <iostream>
using namespace std;
int z = 0; // кількість варіантів розміщення
char check(int A[], int n)
{
int i, j;
for (i = 0; i < n; i++)
@sunmeat
sunmeat / voidstar.cpp
Last active April 30, 2025 18:47
вказівник на невизначений тип void*
#include <iostream>
using namespace std;
void swap(void *a, void *b, size_t size)
{
char *tmp = (char*) malloc(size);
memcpy(tmp, a, size);
memcpy(a, b, size);
memcpy(b, tmp, size);
free(tmp);
@sunmeat
sunmeat / memory_allocation.cpp
Last active May 1, 2025 20:19
malloc calloc realloc free example C++
#include <iostream>
using namespace std;
// функція для демонстрації malloc
void malloc_example() {
system("title malloc example");
int k = 5;
// malloc повертає вказівник на виділену пам'ять, сама пам'ять не ініціалізується
int* ptr = (int*)malloc(k * sizeof(int)); // виділення пам'яті за допомогою malloc
@sunmeat
sunmeat / references.cpp
Last active May 1, 2025 17:46
reference example C++
#include <iostream>
using namespace std;
void vegas(int& a, int& b)
{
// обмін значеннями двох змінних
int temp = a;
a = b;
b = temp;
}
@sunmeat
sunmeat / msize.cpp
Last active May 1, 2025 20:16
_msize example C++
#include <iostream>
using namespace std;
int main() {
setlocale(LC_ALL, "Ukrainian");
int staticArr[10]; // статичний масив
int* dynamicArr = new int[10]; // динамічний масив
@sunmeat
sunmeat / Program.cs
Last active January 8, 2026 18:01
C# assossiation example
using System;
namespace AssociationExample
{
public class Person
{
public string? Name { get; set; } // асоціація (поле з типом іншого класу)
public string? Surname { get; set; }
public string SaySomething() // асоціація (повернення значення з типом іншого класу, string)
{
@sunmeat
sunmeat / Program.cs
Last active January 8, 2026 18:02
aggregation C# example
using System;
namespace AggregationExample
{
public class Hat
{
public string Color { get; set; }
public string Model { get; set; }
public double Price { get; set; }
}
@sunmeat
sunmeat / Program.cs
Last active January 8, 2026 18:02
composition C# example
using System;
namespace CompositionExample
{
public class PegLeg // дерев'яна нога
{
public string Color { get; set; }
public bool Dirty { get; set; }
public double Length { get; set; }
public int Usability { get; set; }