diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..e2c2b2a
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/src/H21.java b/src/H21.java
new file mode 100644
index 0000000..96f210f
--- /dev/null
+++ b/src/H21.java
@@ -0,0 +1,122 @@
+import java.util.Objects;
+import java.util.Scanner;
+
+public class H21 extends HelpCommands {
+
+ public static boolean isGood(Node node) {
+ if (node == null || node.getNext() == null) {
+ return false;
+ }
+ boolean isGoingUPPPP = node.getValue() < node.getNext().getValue();
+ if (isGoingUPPPP) {
+ while (node.getNext() != null) {
+ if (node.getNext().getValue() <= node.getValue()) {
+ return false;
+ }
+ node = node.getNext();
+ }
+ } else {
+ while (node.getNext() != null) {
+ if (node.getNext().getValue() >= node.getValue()) {
+ return false;
+ }
+ node = node.getNext();
+ }
+ }
+ return true;
+ }
+
+ public static int ex26(Node node) {
+ int numof = 0;
+ Node temp = new Node<>(0);
+ while (node != null) {
+ if (node.getValue() == -999) {
+ if (isGood(temp.getNext())) {
+ numof++;
+ }
+ temp = new Node<>(0);
+ }
+ addLast(temp, node.getValue());
+ node = node.getNext();
+ }
+ return numof;
+ }
+
+ public static Node ex35() {
+ Scanner input = new Scanner(System.in);
+ Node node = new Node<>(input.nextInt());
+ while (input.nextInt() != -999) {
+ node.setNext(new Node<>(input.nextInt()));
+ node = sortNodeAllowed(node);
+ }
+ return node;
+ }
+
+ public static int ex37(Node lis1, Node lis2) {
+ while (lis1 != null && lis2 != null) {
+ if (Objects.equals(lis1.getValue(), lis2.getValue())) {
+ return lis1.getValue();
+ }
+ if (lis1.getValue() > lis2.getValue()) {
+ lis2 = lis2.getNext();
+ } else {
+ lis1 = lis1.getNext();
+ }
+ }
+ return -999;
+ }
+
+ public static Node ex38(Node lis1, Node lis2) {
+ Node both = new Node<>(0);
+ Node p = both;
+ while (lis1 != null && lis2 != null) {
+ if (Objects.equals(lis1.getValue(), lis2.getValue())) {
+ p.setNext(new Node<>(lis1.getValue()));
+ p = p.getNext();
+ lis1 = lis1.getNext();
+ lis2 = lis2.getNext();
+ } else if (lis1.getValue() > lis2.getValue()) {
+ lis2 = lis2.getNext();
+ } else {
+ lis1 = lis1.getNext();
+ }
+ }
+ return both.getNext();
+ }
+
+ /*
+ ex39A:
+ [1] = true
+ [1,2] = false
+ B:
+ הפעולה מקבלת רשימה של מספרים, ומחזירה שקר אם הרשימה כוללת שני מספרים (אחד אחרי השני ברשימה) שהמכפלה שלהם גדולה מ0
+ */
+
+ /*
+ ex40
+ A:
+ 30
+ B:
+ הפעולה מחזירה את המספר הגדול ביותר מבין רשימת המספרים שקיבלה
+ */
+
+ public static Node ex49(Node> node){
+ Node finale = new Node<>('@');
+ Node p = finale;
+ while (node != null) {
+ char currentChar = node.getValue().getTav();
+ for (int i = 0; i < node.getValue().getNum(); i++) {
+ p.setNext(new Node<>(currentChar));
+ p = p.getNext();
+ }
+ node = node.getNext();
+ }
+ return finale.getNext();
+ }
+
+ public static void main(String[] args) {
+ Node> exp = buildNodes(new Pair<>('R', 1), new Pair<>('L', 3), new Pair<>('S', 4));
+ printNodes(ex49(exp));
+ }
+
+}
\ No newline at end of file
diff --git a/src/HelpCommands.java b/src/HelpCommands.java
index 9350cd2..8f9d6f0 100644
--- a/src/HelpCommands.java
+++ b/src/HelpCommands.java
@@ -371,17 +371,17 @@ public static Node buildNodes(int n) {
}
/**
- * @param numbers the numbers to put in the node
- * @return a new nodes with the given numbers in order
- */
- public static Node buildNodes(int... numbers) {
- Node ret = new Node<>(0);
- Node p = ret;
- for (int i = 0; i < numbers.length; i++) {
- p.setNext(new Node<>(numbers[i]));
+ * @param values the values to put in the node
+ * @return a new nodes with the given values in order
+ */
+ public static Node buildNodes(T... values) {
+ Node ret = new Node<>(values[0]);
+ Node p = ret;
+ for (int i = 1; i < values.length; i++) {
+ p.setNext(new Node<>(values[i]));
p = p.getNext();
}
- return ret.getNext();
+ return ret;
}
/**
@@ -668,6 +668,13 @@ public static Node nodeAt(Node node, int index) {
return node;
}
+ public static void addLast(Node node, T value){
+ while (node.getNext() != null) {
+ node = node.getNext();
+ }
+ node.setValue(value);
+ }
+
public static BinNode buildBinNode(int n) {
BinNode root = new BinNode((int) (Math.random() * 99) + 1);
BinNode bn = root;
diff --git a/src/Pair.java b/src/Pair.java
new file mode 100644
index 0000000..0c1fc2b
--- /dev/null
+++ b/src/Pair.java
@@ -0,0 +1,28 @@
+public class Pair {
+
+ private Character tav;
+
+ public void setNum(int num) {
+ this.num = num;
+ }
+
+ public void setTav(Character tav) {
+ this.tav = tav;
+ }
+
+ private int num;
+
+ public Pair(Character tav, int num){
+ this.tav = tav;
+ this.num = num;
+ }
+
+ public Character getTav() {
+ return tav;
+ }
+
+ public int getNum() {
+ return num;
+ }
+
+}
diff --git a/src/ex4.png b/src/ex4.png
new file mode 100644
index 0000000..cba4f42
Binary files /dev/null and b/src/ex4.png differ