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 someFunction() { | |
int myVar = 4; | |
} | |
void anotherFunction() { | |
int myVar = 5; | |
std::cout << myVar << std::endl; | |
} |
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 main() { | |
int a = 1; | |
int b = 2; | |
int c = 3; | |
a = a + 1; | |
b = b + 1; | |
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
import java.util.Scanner; | |
public class Solution { | |
public static int getGreatestCommonDivisor(int a, int b) { | |
if (a == b) { | |
return a; | |
} | |
while (a != b) { | |
if (a > b) { |
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 Solution { | |
static int getGreatestCommonDivisor(int a, int b) { | |
while (b != 0) { | |
int temp = a; | |
a = b; | |
b = temp % b; | |
} | |
int greatestCommonDivisor = a; | |
return greatestCommonDivisor; |
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 Solution { | |
static int getGreatestCommonDivisor(int u, int v) { | |
int greatestCommonDivisor = -1; | |
/* 1. | |
* - НОД(0, v) = v, тъй като 0 дели всичко, а v е най-голямото число, което дели v. | |
* - Aналогично, НОД(u, 0) = u. | |
* - НОД(0, 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
public class Solution { | |
static int getGreatestCommonDivisor(int a, int b) { | |
while (b != 0) { | |
int temp = a; | |
a = b; | |
b = temp % b; | |
} | |
int greatestCommonDivisor = a; | |
return greatestCommonDivisor; |
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 Solution { | |
static void sieveOfEratosthenes(int n) { | |
boolean sieve[] = new boolean[n+1]; | |
int i = 2, j = 0; | |
while (i <= n) { | |
if (sieve[i] == false) { | |
System.out.print(i + " "); | |
j = i * 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
/* Optimization ideas: | |
- use less data structures | |
- use less loops etc. | |
*/ | |
import java.util.Scanner; | |
import java.util.List; | |
import java.util.ArrayList; | |
public class Solution { |
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 SelectionSort { | |
public static void selectionSort(int[] arr) { | |
int lastElementIndex = arr.length - 1; | |
for (int subarrayStartIndex = 0; subarrayStartIndex < lastElementIndex; ++subarrayStartIndex) { | |
int minElementIndex = subarrayStartIndex; | |
for (int i = subarrayStartIndex + 1; i < arr.length; ++i) { | |
if (arr[i] < arr[minElementIndex]) { | |
minElementIndex = 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 BubbleSort { | |
public static void bubbleSort(int[] arr) { | |
boolean stillSwappingElements = true; | |
int j = 0; | |
while (stillSwappingElements) { | |
stillSwappingElements = false; | |
j++; | |
for (int i = 0; i < (arr.length - j); ++i) { | |
if (arr[i] > arr[i+1]) { |
OlderNewer