Skip to content

Instantly share code, notes, and snippets.

public Set getPowerset(Set set) {
Set powerset = new HashSet();
powerset.add(new HashSet()); // Add the empty set
getPset(set.toArray(), new HashSet(), powerset, set.size(), 0);
return powerset;
}
private void getPset(Object[] input, Set subset, Set powerset, int n, int start) {
for (int i = start; i < n; i++) {
Object o = input[i];
var express = require('../..');
var app = module.exports = express();
// settings
// map .renderFile to ".html" files
app.engine('html', require('ejs').renderFile);
// make ".html" the default
In computer science, the producer-consumer problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer. The producer's job is to generate a piece of data, put it into the buffer and start again. At the same time the consumer is consuming the data (i.e. removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer.

The solution for the producer is to go to sleep if the buffer is full. The next time the consumer removes an item from the buffer, it wakes up the producer who starts to fill the buffer again. In the same way the consumer goes to sleep if it finds the buffer to be empty. The next time the producer puts data into the buffer, it wakes up the sleeping consumer. The solution can be rea
class MyQueue {
public static void main(String[] args) {
System.out.println("!");
Queue q = new Queue();
q.enqueue(0);
q.enqueue(1);
q.enqueue(3);
q.enqueue(2);
q.enqueue(1);
q.enqueue(0);
class MyQueue {
public static void main(String[] args) {
System.out.println("!");
Queue q = new Queue();
q.enqueue(1);
q.enqueue(2);
q.enqueue(2);
q.enqueue(2);
q.enqueue(3);
q.enqueue(2);
@adrianlee
adrianlee / MyQueue.java
Created January 5, 2013 23:25
Implement a queue
class MyQueue {
public static void main(String[] args) {
System.out.println("!");
Queue q = new Queue();
q.enqueue(1);
q.enqueue(2);
q.enqueue(2);
q.enqueue(2);
q.enqueue(3);
q.enqueue(2);
@adrianlee
adrianlee / Stack.java
Created January 5, 2013 23:07
Implementing a stack
class Stack {
public static void main(String[] args) {
System.out.println("!");
MyStack n = new MyStack();
n.push(1);
n.push(2);
System.out.println(n.pop().data); // prints 2
System.out.println(n.pop().data); // prints 1
}
}
http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
This Java tutorial may be of some use to you.
Modifier | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public | ✔ | ✔ | ✔ | ✔
————————————+———————+—————————+——————————+———————
protected | ✔ | ✔ | ✔ | ✘
————————————+———————+—————————+——————————+———————
// Bind in its simplest form
function bind(scope, fn) {
return function () {
return fn.apply(scope, toArray(arguments));
};
}
Given a circular linked list, implement an algorithm which returns node at the begin- ning of the loop.
DEFINITION
Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list.
EXAMPLE
Input: A -> B -> C -> D -> E -> C [the same C as earlier]
Output: C