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
121 changes: 121 additions & 0 deletions src/Matconet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import classes.Vote;
import utils.BinNode;
import utils.Queue;

import java.util.Arrays;

public class Matconet extends Main {

public static int lastOddNum(int[] arr){
int lastOddNum = -1;
for (int j : arr) {
if (j % 2 == 1) {
lastOddNum = j;
}
}
return lastOddNum;
}

// //O(n*z§k) n is nodes in t1 and k is nodes in t2
// public static boolean treeLessThanTree(BinNode<Integer> t1, BinNode<Integer> t2){
// if (t1 == null) {
// return true;
// }
// if (!lessThanTree(t2, t1.getValue())) {
// return false;
// }
// return treeLessThanTree(t1.getLeft(), t2) && treeLessThanTree(t1.getRight(), t2);
// }

public static int theWinner(Vote[] arr){
int[] votes = new int[40];
for (Vote vote : arr){
votes[vote.getFirst()] += 7;
votes[vote.getSecond()] += 5;
votes[vote.getThird()] += 1;
}
int max = -1;
int maxSong = -1;
for (int i = 0; i < votes.length; i++) {
if (votes[i] > max) {
max = votes[i];
maxSong = i;
}
}
return maxSong;
}

public static int checkX(Queue<Integer> q, int x){
Queue<Integer> t = new Queue<>();
int count = 0;
while (!q.isEmpty()) {
if (q.head() == x) {
q.remove();
count++;
} else {
t.insert(q.remove());
}
}
while (!t.isEmpty()) {
q.insert(t.remove());
}
return count;
}

public static Queue<Integer> sortQueuee(Queue<Integer> queue){
Queue<Integer> ret = new Queue<>();
while (!queue.isEmpty()) {
int currentVal = queue.head();
int countOfVal = checkX(queue, currentVal);
for (int i = 0; i < countOfVal; i++) {
ret.insert(currentVal);
}
}
return ret;
}

public static void move(Queue<Integer> q){
Queue<Integer> negative = new Queue<>();
Queue<Integer> zeros = new Queue<>();
Queue<Integer> positive = new Queue<>();
while (!q.isEmpty()) {
if (q.head() == 0) {
zeros.insert(q.remove());
} else if (q.head() > 0) {
positive.insert(q.remove());
} else {
negative.insert(q.remove());
}
}
while (!positive.isEmpty()) {
q.insert(positive.remove());
}
while (!zeros.isEmpty()) {
q.insert(zeros.remove());
}
while (!negative.isEmpty()) {
q.insert(negative.remove());
}
}

public static Queue<Integer> queCouples(Queue<Integer> queue){
Queue<Integer> clone = copyQueue(queue);
Queue<Integer> ret = new Queue<>();
while (!clone.isEmpty()) {
int currentVal = clone.head();
if (checkX(queue, currentVal) == 2) {
ret.insert(currentVal);
}
}
return ret;
}





public static void main(String[] args) {
int[] a = {1,1,1,1,1,1,1,1,5,-1,2};
System.out.println(Arrays.toString(Arrays.stream(a).sorted().toArray()));
}
}
27 changes: 27 additions & 0 deletions src/classes/Airport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package classes;

import java.util.Arrays;

public class Airport {

private Flight[] arr;

public Airport(Flight[] arr) {
this.arr = arr;
}

public Flight[] getArr() {
return arr;
}

public void setArr(Flight[] arr) {
this.arr = arr;
}

@Override
public String toString() {
return "Airport{" +
"arr=" + Arrays.toString(arr) +
'}';
}
}
59 changes: 59 additions & 0 deletions src/classes/Flight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package classes;

public class Flight {

private String name;
private String destination;
private String flightCode;
private Time flightTime;

public Flight(String name, String destination, String flightCode, Time flightTime) {
this.name = name;
this.destination = destination;
this.flightCode = flightCode;
this.flightTime = flightTime;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDestination() {
return destination;
}

public void setDestination(String destination) {
this.destination = destination;
}

public String getFlightCode() {
return flightCode;
}

public void setFlightCode(String flightCode) {
this.flightCode = flightCode;
}

public Time getFlightTime() {
return flightTime;
}

public void setFlightTime(Time flightTime) {
this.flightTime = flightTime;
}

@Override
public String toString() {
return "Flight{" +
"name='" + name + '\'' +
", destination='" + destination + '\'' +
", flightCode='" + flightCode + '\'' +
", flightTime=" + flightTime +
'}';
}

}
3 changes: 3 additions & 0 deletions src/classes/Persoon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package classes;

public record Persoon(String name, int id, int phoneNum) {}
36 changes: 36 additions & 0 deletions src/classes/Time.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package classes;

public class Time {

private int hour;
private int minute;

public Time(int hour, int minute) {
this.hour = hour > 23 || hour < 0 ? 0 : hour;
this.minute = minute > 59 || minute < 0 ? 0 : minute;
}

public int getHour() {
return hour;
}

public void setHour(int hour) {
this.hour = hour;
}

public int getMinute() {
return minute;
}

public void setMinute(int minute) {
this.minute = minute;
}

@Override
public String toString() {
return "Time{" +
"hour=" + hour +
", minute=" + minute +
'}';
}
}
47 changes: 47 additions & 0 deletions src/classes/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package classes;

public class Vote {

private int first;
private int second;
private int third;

public Vote(int first, int second, int third) {
this.first = first;
this.second = second;
this.third = third;
}

public int getFirst() {
return first;
}

public void setFirst(int first) {
this.first = first;
}

public int getSecond() {
return second;
}

public void setSecond(int second) {
this.second = second;
}

public int getThird() {
return third;
}

public void setThird(int third) {
this.third = third;
}

@Override
public String toString() {
return "Vote{" +
"first=" + first +
", second=" + second +
", third=" + third +
'}';
}
}
39 changes: 39 additions & 0 deletions src/classes/WaitingList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package classes;

import utils.Queue;

public class WaitingList {

private Queue<Persoon> green;
private Queue<Persoon> red;

public WaitingList(){
green = new Queue<>();
red = new Queue<>();
}

public void insert(Persoon persoon, int k){
if (k == 1) {
green.insert(persoon);
} else if (k == 2) {
red.insert(persoon);
}
}

public Persoon remove(){
if (green.isEmpty()) {
return red.remove();
}
return green.remove();
}

public boolean isEmpty(){
return green.isEmpty() && red.isEmpty();
}

@Override
public String toString(){
return "Green queue: " + green + "\n" + "Red queue: " + red;
}

}
8 changes: 8 additions & 0 deletions src/utils/HelpCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ public static Queue<Integer> buildQueue(int n, int max) {
return queue;
}

public static <T> Queue<T> buildQueue(T... values){
Queue<T> queue = new Queue<>();
for (T value : values){
queue.insert(value);
}
return queue;
}

/**
* @param queue
* @return the length of the queue
Expand Down