Skip to content

Instantly share code, notes, and snippets.

View jyhjuzi's full-sized avatar

Yanhong Ju jyhjuzi

  • China
View GitHub Profile
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
public class Q4_2 {
public static void main(String[] args) {
NodeWithState nodea = new NodeWithState("a");
NodeWithState nodeb = new NodeWithState("b");
NodeWithState nodec = new NodeWithState("c");
public class Q4_1{
public static void main(String[] args){
BST<Integer> tree = new BST<Integer>(new TreeNode(15,null,null));
for(int i = 9; i<20; i=i+10){
tree.insert(i);
tree.insert(i-2);
tree.insert(i+2);
}
tree.insert(6);
tree.insert(8);
import java.util.LinkedList;
public class Q3_7{
public static void main(String[] args){
Dog[] dogs = {new Dog("doga"),new Dog("dogb"),new Dog("dogc"),new Dog("dogd"),new Dog("doge")};
Cat[] cats = {new Cat("cata"),new Cat("catb"),new Cat("catc")};
AnimalShelter ash = new AnimalShelter();
ash.enqueue(dogs[0]);
ash.enqueue(dogs[1]);
System.out.println(ash.dequeueDog().name);
import java.util.Stack;
public class Q3_6{
public static void main(String[] args){
Stack<Integer> test = new Stack<Integer>();
test.push(5);
test.push(2);
test.push(3);
import java.util.Stack;
public class Q3_5{
public static void main(String[] args){
MyQueue<Integer> test = new MyQueue<Integer>();
test.enqueue(1);
test.enqueue(2);
System.out.println(test.dequeue());
test.enqueue(3);
System.out.println(test.dequeue());
System.out.println(test.dequeue());
import java.util.Stack;
public class Q3_4{
public static void main(String[] args){
Tower source = new Tower(new int[] {4,3,2,1},0);
Tower tool = new Tower(new int[0],1);
Tower des = new Tower(new int[0],2);
source.moveTo(des,tool,source.stack.size());
}
import java.util.ArrayList;
public class Q3_3{
public static void main(String[] args ){
int capacity_per_substack = 5;
SetsOfStacks set = new SetsOfStacks(capacity_per_substack);
for (int i = 0; i < 45; i++) {
set.push(i+" ");
}
for (int i = 0; i < 6; i++) {
import java.util.Stack;
public class Q3_2{
public static void main(String args[]){
StackWithMin s = new StackWithMin();
s.push(5);
s.push(4);
s.push(6);
s.push(7);
s.push(2);
public class Q3_1 {
public static void main(String args[]) throws Exception {
ThreeStacks test = new ThreeStacks(30);
test.push(2, 4);
System.out.println("Peek 2: " + test.peek(2));
test.push(0, 3);
test.push(0, 7);
test.push(0, 5);
System.out.println("Peek 0: " + test.peek(0));
test.pop(0);
import java.util.Stack;
public class Q2_7{
public static void main(String args[]){
Q2_7 test = new Q2_7();
LLNode head = new LLNode("1",null);
head.next = new LLNode("1",new LLNode("3", new LLNode("2",new LLNode("1", null))));