Created
November 13, 2013 13:55
-
-
Save dimkir/7449487 to your computer and use it in GitHub Desktop.
Processing sketch : stackIterator
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
Stack<String> stack; | |
void draw(){ | |
background(0); | |
text(stack.pop(), width/2, height/2 ); | |
stack.push(mouseX + ", " + mouseY); | |
} |
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
int CW = 800; | |
int CH = 600; | |
void setup(){ | |
size(CW, CH); | |
stack = new Stack(); | |
stack.push("Hello"); | |
} |
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
//#GIST:7449487 | |
import java.util.Iterator; | |
class Stack<Item> | |
implements Iterable<Item> | |
{ | |
Node<Item> current; | |
Iterator<Item> iterator(){ | |
return new StackIterator<Item>(); | |
// return null; | |
} | |
boolean isEmpty(){ | |
return ( current == null); | |
} | |
void push(Item it){ | |
Node<Item> n = new Node<Item>(current, it); | |
current = n; | |
} | |
Item pop(){ | |
if ( current == null){ | |
throw new RuntimeException("Can't pop, stack is null"); | |
} | |
Item res = current.item; | |
current = current.next; | |
return res; | |
} | |
class StackIterator<Item1> implements Iterator<Item1> | |
{ | |
boolean hasNext(){ | |
throw new RuntimeException("un"); | |
} | |
Item1 next(){ | |
throw new RuntimeException("un"); | |
} | |
void remove(){ | |
throw new RuntimeException("un"); | |
} | |
} | |
} | |
class Node<Item> | |
{ | |
Node next; | |
Item item; | |
Node(Node node, Item it){ | |
next = node; | |
item = it; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment