Skip to content

Instantly share code, notes, and snippets.

View SashaB2's full-sized avatar

Sasha SashaB2

  • Ukraine, Kyiv
View GitHub Profile
@SashaB2
SashaB2 / PHP compare recursively two arrays
Last active November 19, 2022 14:45
PHP compare recursively two arrays
<?php
namespace mynamespace;
class ArrayRecurseComparator
{
public function compareArraysRecursively($actual, $expected)
{
$trigger = true;
<?php
/**
* 1. World War I: 28 07 1914
* 28+07+19+14= 68
* 2. World War II: 01 09 1939
* 01+09+19+39= 68
* 3. World War III(russia invasion in of Ukraine): 24 02 2022
* 24+02+20+22= 68
*/
#!/bin/bash
#arg1 integer
#arg2 integer
gcd(){
local a=$1
local b=$2
@SashaB2
SashaB2 / CursorSixTask.txt
Last active July 17, 2019 18:36
CursorSixTask
2)Пояснити що таке Comparator i Comparable:
Comparable - This interface has one method compareTo. Class whose objects to be sorted must implement this Comparable interface. In this case there is one form or way of sorting, e.g. We can sort players by age, so if we want to sort them by ranking or by name, in this case we have to change our Player class and change compareTo method to do that.
Comparator - This interface has two methods equals and compare. Class whose objects to be sorted do not need to implement this Comparator interface. Some third class can implement this interface to sort. In this case there are multiple forms of sorting, we can write different sorting based on different attributes of objects to be sorted, e.g. We can sort players by age, by ranking, and by namewithout change our Player class, to do that we use other class for Age Comparison and other class for Ranking Comparison and other class for Name Comparison.
3) Чому в PriorityQueue MAX capacity - MAX_INTEGER- 8? - Some VMs rese
1. https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html
2. https://stackoverflow.com/questions/19782314/why-cant-arrays-be-resized
When you create an array, using int[] array = new int[5] for instance, the computer reserves five consecutive spaces in
memory for the data to be contained in that array. However, the spaces in memory after that can be used right away to
store other information. If the array were to be resized later on, that other information would have to be moved somewhere
else in order for the array to get bigger. That's a lot of shuffling that we don't want to deal with, so computer architects
disallow array resizing to make things simpler.
import java.util.*;
public class HomeTaskThree {
public static void main(String[] args) {
//Task - 1,2 - I have read about it.
//Task - 3. DESC sorting of arr of integers
Integer [] arr0 = new Integer[]{2, 3, 1, 7, 11};
@SashaB2
SashaB2 / ReadLinesFromFile.java
Created June 15, 2018 20:04
ReadLinesFromFile
package com.javarush.task.task15.task1525;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Файл в статическом блоке
*/
public class Solution {
public static void main(String[] args) {
Singleton s = Singleton.getInstance();
@SashaB2
SashaB2 / FileInOut.java
Created May 19, 2018 09:26
FileInOut.java
public static void main(String[] args) throws IOException
{
InputStream inStream = new FileInputStream("c:/source.txt");
OutputStream outStream = new FileOutputStream("c:/result.txt");
while (inStream.available() > 0)
{
int data = inStream.read(); //читаем один байт из потока для чтения
outStream.write(data); //записываем прочитанный байт в другой поток.
}
package com.javarush.task.task11.task1123;
public class Solution {
public static void main(String[] args) throws Exception {
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5};
Pair<Integer, Integer> result = getMinimumAndMaximum(data);
System.out.println("Minimum is " + result.x);
System.out.println("Maximum is " + result.y);