Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/14a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/14b1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/14b2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/15a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/15b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/15c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/1a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/4a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/4b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions src/L26.java
Original file line number Diff line number Diff line change
@@ -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<Student> getStudentsByMonth(School s, int month) {
Node<Student> ret = new Node<>(new Student("-1", new Birth(-1, -1, -1)));
Node<Student> p = ret;
for (Node<Student> 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<Student>[] ex3(School s) {
Node<Student>[] 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 <T> boolean isBalanced(BinNode<T> 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<Integer> root1 = buildTree(1);
BinNode<Integer> root2 = buildTree(1, 2, 3, 4);
BinNode<Integer> root3 = buildTree(1, 2, 3, 4, 5, 6);
BinNode<Integer> 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<Student> 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<Student> 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<Student> 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<Student> 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<Student> 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<Student> 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<Student>[] ex3 = ex3(s);

for (Node<Student> n : ex3) {
System.out.println(n);
}
}

}
47 changes: 47 additions & 0 deletions src/classes/Birth.java
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
45 changes: 45 additions & 0 deletions src/classes/Collec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package classes;

import utils.Queue;

public class Collec {

private Queue<Integer> 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 +
'}';
}
}
29 changes: 29 additions & 0 deletions src/classes/School.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package classes;

import utils.Node;

import java.util.Arrays;

public class School {

private Node<Student>[] ar;

public School(Node<Student>[] ar) {
this.ar = ar;
}

public Node<Student>[] getAr() {
return ar;
}

public void setAr(Node<Student>[] ar) {
this.ar = ar;
}

@Override
public String toString() {
return "School{" +
"ar=" + Arrays.toString(ar) +
'}';
}
}
36 changes: 36 additions & 0 deletions src/classes/Student.java
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}