This file contains hidden or 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
| #include <iostream> | |
| #include <sstream> | |
| #include <v8.h> | |
| using namespace v8; | |
| int main(int argc, const char **argv) { | |
| // Create a scope and environment | |
| HandleScope scope; | |
| Handle<Context> context = Context::New(); |
This file contains hidden or 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
| # Programming Pearls: column 14 | |
| class Heaps(object): | |
| """ | |
| >>> h = Heaps() | |
| >>> len(h) | |
| 0 | |
| >>> h.extend([12, 20, 15, 3, 13, 23]) | |
| >>> len(h) | |
| 6 |
This file contains hidden or 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.NoSuchElementException; | |
| /** | |
| * A binary heap is a heap data structure create using a binary tree. | |
| * | |
| * @author Takanori Ishikawa <takanori.ishikawa@gmail.com> | |
| */ | |
| public class BinaryHeap<E extends Comparable<E>> { | |
| private E[] items; |
This file contains hidden or 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
| /** | |
| * Heapsort (method) is a comparison-based sorting algorithm, | |
| * and is part of the selection sort family. Although somewhat | |
| * slower in practice on most machines than a good implementation of | |
| * quicksort, it has the advantage of a worst-case Θ(n log n) runtime. | |
| * Heapsort is an in-place algorithm, but is not a stable sort. | |
| * | |
| * @author ishikawa | |
| * |
This file contains hidden or 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
| package org.metareal; | |
| import java.util.NoSuchElementException; | |
| public class LinkedList <E> { | |
| private final Node<E> head; | |
| private Node<E> tail; | |
| public LinkedList() { |
This file contains hidden or 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
| /** | |
| * http://en.wikipedia.org/wiki/Queue_(data_structure) | |
| */ | |
| public class Queue <E> { | |
| private LinkedList<E> elements = new LinkedList<E>(); | |
| public int size() { return elements.size(); } | |
| public boolean isEmpty() { return elements.isEmpty(); } | |
| public E front() { return elements.get(0); } | |
| public E pop() { return elements.removeFirst(); } |
This file contains hidden or 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
| /** | |
| * http://en.wikipedia.org/wiki/Stack_(data_structure) | |
| */ | |
| public class Stack <E> { | |
| private LinkedList<E> elements = new LinkedList<E>(); | |
| public int size() { return elements.size(); } | |
| public boolean isEmpty() { return elements.isEmpty(); } | |
| public E top() { return elements.get(0); } | |
| public E pop() { return elements.removeFirst(); } |
This file contains hidden or 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
| package org.metareal.graph; | |
| import org.metareal.LinkedList; | |
| import org.metareal.Queue; | |
| import org.metareal.Stack; | |
| public class GraphSearchAlgorithm { | |
| private final LinkedList<Integer>[] vertices; | |
This file contains hidden or 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
| /* | |
| * Programming Pearls 2nd Edition | |
| * Column 5: Binary Search | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| #include <assert.h> | |
This file contains hidden or 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
| def compile_python_source(filepath, optimization=False): | |
| """ | |
| Compile a source file to byte-code and write out | |
| the byte-code cache file. The source code is loaded | |
| from the file name *filepath*. The byte-code is cached | |
| in the normal manner (*filepath* + 'c' or 'o' if | |
| optimization is enabled). | |
| """ | |
| from os import spawnv | |
| from sys import executable, platform |