Skip to content

Instantly share code, notes, and snippets.

View adyatlov's full-sized avatar

Andrey Dyatlov adyatlov

View GitHub Profile
#include <stdio.h>
#include <string.h>
union FloatByteStorage {
char bytes[4];
float number;
};
int main(int, char**) {
FloatByteStorage storage;
Посмотри на площади дым и огни
Твоё имя лозунгом новым звучит
Сколько б мы не плакали,вас уже нет
Кто нам сможет дать ответ?
Равнодушных больше нет,время пришло
На какой ты стороне:добро или зло?
Чтобы мы не сделали вас не вернуть, и на всех один лишь путь.
Кто если не я,если не ты
Сделает первый шаг для своей страны
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
TreeItem findStack(TreeItem root, Object obj) {
Deque<TreeItem> stack = new ArrayDeque<TreeItem>();
stack.push(root);
while (!stack.isEmpty()) {
TreeItem currentItem = stack.pop();
if (Objects.equals(currentItem.getData(), obj)) {
return currentItem;
}
for (TreeItem child : currentItem.getChildren()) {
stack.push(child);
TreeItem findStack2(TreeItem root, Object obj) {
maxStackSize = 0;
Deque<Iterator<TreeItem>> stack = new ArrayDeque<Iterator<TreeItem>>();
stack.push(Collections.singletonList(root).iterator());
while (!stack.isEmpty()) {
Iterator<TreeItem> it = stack.peek();
if (it.hasNext()) {
TreeItem item = it.next();
if (Objects.equals(item.getData(), obj)) {
return item;
package com.company;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class Main {
private int n = 100000;
private int depth = 0;
private int maxStackSize = 0;
private int currStackSize = 0;
@adyatlov
adyatlov / merge_sort.cpp
Last active August 29, 2015 14:02
C++ implementation of Merge sort
#include <vector>
#include <iterator>
#include <algorithm>
template<typename Iterator>
std::vector<typename Iterator::value_type> mergeSort(Iterator begin, Iterator end) {
if (begin == end) {
return std::vector<typename Iterator::value_type>();
}
auto n = std::distance(begin, end);
@adyatlov
adyatlov / intervals.js
Created December 21, 2014 15:49
Simple library to check if intervals intersect. Support open, closed and partially closed intervals. Dedicated to Alex. Tests are here https://gist.github.com/benzel/ffb0851c6e22469cf662
Boundary = function (value, type) {
this.value = value;
this.type = type;
}
Boundary.weightTable = {
")": 1,
"]": 2,
"[": 2,
"(": 3
"use strict";
describe("Test Boundary", function() {
var bol0 = new Boundary(0, "(");
var bor0 = new Boundary(0, ")");
var bcl0 = new Boundary(0, "[");
var bcr0 = new Boundary(0, "]");
var bol1 = new Boundary(1, "(");
var bor1 = new Boundary(1, ")");
var bcl1 = new Boundary(1, "[");
for (Job* job: jobs) {
for (ComputeNode* node: nodes) {
if (node->scheduleJob(job)) {
break;
}
}
}