diff --git a/src/13.png b/src/13.png new file mode 100644 index 0000000..4c5b07f Binary files /dev/null and b/src/13.png differ diff --git a/src/14a.png b/src/14a.png new file mode 100644 index 0000000..1504252 Binary files /dev/null and b/src/14a.png differ diff --git a/src/14b1.png b/src/14b1.png new file mode 100644 index 0000000..5e9823d Binary files /dev/null and b/src/14b1.png differ diff --git a/src/14b2.png b/src/14b2.png new file mode 100644 index 0000000..6c2c6a2 Binary files /dev/null and b/src/14b2.png differ diff --git a/src/15a.png b/src/15a.png new file mode 100644 index 0000000..2bdc1e8 Binary files /dev/null and b/src/15a.png differ diff --git a/src/15b.png b/src/15b.png new file mode 100644 index 0000000..d0cd321 Binary files /dev/null and b/src/15b.png differ diff --git a/src/15c.png b/src/15c.png new file mode 100644 index 0000000..1f2a460 Binary files /dev/null and b/src/15c.png differ diff --git a/src/16.png b/src/16.png new file mode 100644 index 0000000..f17775d Binary files /dev/null and b/src/16.png differ diff --git a/src/1a.png b/src/1a.png new file mode 100644 index 0000000..43b399a Binary files /dev/null and b/src/1a.png differ diff --git a/src/4a.png b/src/4a.png new file mode 100644 index 0000000..9b15a53 Binary files /dev/null and b/src/4a.png differ diff --git a/src/4b.png b/src/4b.png new file mode 100644 index 0000000..7a80b07 Binary files /dev/null and b/src/4b.png differ diff --git a/src/L26.java b/src/L26.java new file mode 100644 index 0000000..2fb2b94 --- /dev/null +++ b/src/L26.java @@ -0,0 +1,141 @@ +import classes.Birth; +import classes.Collec; +import classes.School; +import classes.Student; +import utils.BinNode; +import utils.Node; +import utils.Queue; + +public class L26 extends Main { + + public static Node getStudentsByMonth(School s, int month) { + Node ret = new Node<>(new Student("-1", new Birth(-1, -1, -1))); + Node p = ret; + for (Node n : s.getAr()) { + while (n != null) { + if (n.getValue().getBirthDay().getMonth() == month) { + p.setNext(new Node<>(n.getValue())); + p = p.getNext(); + } + n = n.getNext(); + } + } + return ret.getNext(); + } + + public static Node[] ex3(School s) { + Node[] ret = new Node[12]; + int[] months = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + for (int m : months) { + ret[m - 1] = getStudentsByMonth(s, m); + } + return ret; + } + + public static boolean isBalanced(BinNode root) { + if (root == null) { + return true; + } + if (Math.abs(getTreeHeight(root.getRight()) - getTreeHeight(root.getLeft())) > 1) { + return false; + } + return isBalanced(root.getLeft()) && isBalanced(root.getRight()); + } + + public static void main(String[] args) { + System.out.println(2%3); + } + + public static void checkCollec(){ + Collec collec = new Collec(); + System.out.println(collec.add(2)); + System.out.println(collec.add(3)); + System.out.println(collec.add(4)); + System.out.println(collec.add(5)); + System.out.println(collec.add(2)); + System.out.println(collec.small()); + Collec collec1 = new Collec(5); + System.out.println(collec1.add(4)); + System.out.println(collec1.add(5)); + System.out.println(collec1.add(6)); + System.out.println(collec.smallest(collec1)); + Collec collec2 = new Collec(1); + System.out.println(collec.smallest(collec2)); + + + } + + public static void isBalancedCheck() { + BinNode root1 = buildTree(1); + BinNode root2 = buildTree(1, 2, 3, 4); + BinNode root3 = buildTree(1, 2, 3, 4, 5, 6); + BinNode root4 = buildTree(1, 2, 3, 4, 5, 6, 7); + + printMeTree(root1); + printMeTree(root2); + printMeTree(root3); + printMeTree(root4); + + System.out.println(isBalanced(root1)); + System.out.println(isBalanced(root2)); + System.out.println(isBalanced(root3)); + System.out.println(isBalanced(root4)); + } + + public static void ex3Check() { + Node grade1 = buildNodes( + new Student("a", new Birth(1, 1, 1)), + new Student("b", new Birth(1, 2, 1)), + new Student("c", new Birth(1, 3, 1)), + new Student("d", new Birth(1, 4, 1)) + ); + Node grade2 = buildNodes( + new Student("e", new Birth(1, 5, 1)), + new Student("f", new Birth(1, 6, 1)), + new Student("g", new Birth(1, 7, 1)), + new Student("h", new Birth(1, 8, 1)) + ); + Node grade3 = buildNodes( + new Student("i", new Birth(1, 9, 1)), + new Student("j", new Birth(1, 10, 1)), + new Student("k", new Birth(1, 11, 1)), + new Student("l", new Birth(1, 12, 1)) + ); + Node grade4 = buildNodes( + new Student("m", new Birth(1, 1, 1)), + new Student("n", new Birth(1, 2, 1)), + new Student("o", new Birth(1, 3, 1)), + new Student("p", new Birth(1, 4, 1)) + ); + Node grade5 = buildNodes( + new Student("q", new Birth(1, 5, 1)), + new Student("r", new Birth(1, 6, 1)), + new Student("s", new Birth(1, 7, 1)), + new Student("t", new Birth(1, 8, 1)) + ); + Node grade6 = buildNodes( + new Student("u", new Birth(1, 9, 1)), + new Student("w", new Birth(1, 10, 1)), + new Student("x", new Birth(1, 11, 1)), + new Student("y", new Birth(1, 12, 1)) + ); + + School s = new School( + new Node[]{ + grade1, + grade2, + grade3, + grade4, + grade5, + grade6 + } + ); + + Node[] ex3 = ex3(s); + + for (Node n : ex3) { + System.out.println(n); + } + } + +} diff --git a/src/classes/Birth.java b/src/classes/Birth.java new file mode 100644 index 0000000..2e5c4f8 --- /dev/null +++ b/src/classes/Birth.java @@ -0,0 +1,47 @@ +package classes; + +public class Birth { + + private int day; + private int month; + private int year; + + public Birth(int day, int month, int year) { + this.day = day; + this.month = month; + this.year = year; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + @Override + public String toString() { + return "Birth{" + + "day=" + day + + ", month=" + month + + ", year=" + year + + '}'; + } +} diff --git a/src/classes/Collec.java b/src/classes/Collec.java new file mode 100644 index 0000000..4bb7df9 --- /dev/null +++ b/src/classes/Collec.java @@ -0,0 +1,45 @@ +package classes; + +import utils.Queue; + +public class Collec { + + private Queue queue; + private int biggest; + + public Collec(){ + this.queue = new Queue<>(); + biggest = 0; + } + + public Collec(int n){ + this.queue = new Queue<>(); + queue.insert(n); + biggest = n; + } + + public boolean add(int n){ + if (n > biggest) { + queue.insert(n); + biggest = n; + return true; + } + return false; + } + + public int small(){ + return queue.isEmpty() ? -1 : queue.head(); + } + + public int smallest(Collec other){ + return Math.min(small(), other.small()); + } + + @Override + public String toString() { + return "Collec{" + + "queue=" + queue + + ", biggest=" + biggest + + '}'; + } +} diff --git a/src/classes/School.java b/src/classes/School.java new file mode 100644 index 0000000..9433184 --- /dev/null +++ b/src/classes/School.java @@ -0,0 +1,29 @@ +package classes; + +import utils.Node; + +import java.util.Arrays; + +public class School { + + private Node[] ar; + + public School(Node[] ar) { + this.ar = ar; + } + + public Node[] getAr() { + return ar; + } + + public void setAr(Node[] ar) { + this.ar = ar; + } + + @Override + public String toString() { + return "School{" + + "ar=" + Arrays.toString(ar) + + '}'; + } +} diff --git a/src/classes/Student.java b/src/classes/Student.java new file mode 100644 index 0000000..58d0f16 --- /dev/null +++ b/src/classes/Student.java @@ -0,0 +1,36 @@ +package classes; + +public class Student { + + private String name; + private Birth birthDay; + + public Student(String name, Birth birthDay) { + this.name = name; + this.birthDay = birthDay; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Birth getBirthDay() { + return birthDay; + } + + public void setBirthDay(Birth birthDay) { + this.birthDay = birthDay; + } + + @Override + public String toString() { + return "Student{" + + "name='" + name + '\'' + + ", birthDay=" + birthDay + + '}'; + } +}