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
class Tree { | |
public Tree left; // левое и правое поддеревья и ключ | |
public Tree right; | |
public int key; | |
public Tree(int k) { // конструктор с инициализацией ключа | |
key = k; | |
} | |
/* insert (добавление нового поддерева (ключа)) |
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.lang.instrument.Instrumentation; | |
public class ObjectSizeFetcher { | |
private static Instrumentation instrumentation; | |
public static void premain(String args, Instrumentation inst) { | |
instrumentation = inst; | |
} | |
public static long getObjectSize(Object o) { |
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.io.BufferedReader; | |
import java.io.DataInputStream; | |
import java.io.IOException; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.util.regex.Pattern; | |
import java.util.regex.Matcher; |
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
class LazyCalc: | |
def __init__(self): | |
self.dict = {} | |
def calc(self, n): | |
if n not in self.dict: | |
def recursion(n): | |
if n <= 1: | |
return 1 |
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
class Component: | |
def draw(self): | |
raise NotImplementedError() | |
def add(self, component): | |
raise ComponentError() | |
def remove(self, component): | |
raise ComponentError() |
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
class Context: | |
def __init__(self, state): | |
try: | |
self.state = state | |
except WrongStateError: | |
pass | |
def register(self): | |
try: | |
self.state.register(self) |
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
class Command: | |
def execute(self): | |
raise NotImplementedError() | |
class Accelerator(Command): | |
def __init__(self, car): | |
self.car = car | |
def execute(self): |
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
from copy import deepcopy | |
class Prototype: | |
def __init__(self, example): | |
self.example = example | |
def clone(self): | |
return deepcopy(self.example) | |
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
class Product: | |
pass | |
class FordCar(Product): | |
pass | |
class ToyotaCar(Product): | |
pass | |
class Factory: |
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
# -*- coding: utf-8 -*- | |
class AbstractCarFactory: | |
"""Абстрактная фабрика""" | |
def createCar(self): | |
raise NotImplementedError() | |
class FordFactory(AbstractCarFactory): | |
"""Конкретная фабрика A""" | |
def createCar(self): |