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.*;
public class Q2_5{
public static void main(String args[]){
LinkedList<Integer> test1 = new LinkedList<Integer>();
LinkedList<Integer> test2 = new LinkedList<Integer>();
test1.add(6);
test1.add(1);
test1.add(7);
test2.add(2);
test2.add(9);
public class Q2_6 {
public static void main(String args[]) {
Node head = new Node(0);
Node n1 = new Node(1);
Node n2 = new Node(2);
Node n3 = new Node(3);
Node n4 = new Node(4);
head.next = n1;
n1.next = n2;
n2.next = n3;
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))));
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 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);
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_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.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_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.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);