From 26f72e80e5f605eb1183797dd655243338fb1f15 Mon Sep 17 00:00:00 2001 From: drorta <125767200+drorta@users.noreply.github.com> Date: Tue, 6 May 2025 14:48:41 +0300 Subject: [PATCH 1/2] c --- src/L28.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/L28.java diff --git a/src/L28.java b/src/L28.java new file mode 100644 index 0000000..33d920f --- /dev/null +++ b/src/L28.java @@ -0,0 +1,7 @@ +public class L28 extends Main { + + public static void main(String[] args) { + + } + +} From 3a4dd7330873ed3ecb1e3f597c8423f9b31ab7f7 Mon Sep 17 00:00:00 2001 From: drorta <125767200+drorta@users.noreply.github.com> Date: Tue, 13 May 2025 14:31:12 +0300 Subject: [PATCH 2/2] a --- src/L28.java | 18 +++++++++++++++++- src/utils/HelpCommands.java | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/L28.java b/src/L28.java index 33d920f..7951119 100644 --- a/src/L28.java +++ b/src/L28.java @@ -1,7 +1,23 @@ +import utils.Queue; + public class L28 extends Main { - public static void main(String[] args) { + public static int sumH(Queue queue) { + int x = queue.remove(); + if (queue.head() > x) { + queue.insert(x); + return queue.head() - x + sumH(queue); + } else { + queue.insert(x); + return 0; + } + } + public static void main(String[] args) { + Queue queue = buildQueue(1,4,8,17,20); + System.out.println(queue); + System.out.println(sumH(queue)); + System.out.println(queue); } } diff --git a/src/utils/HelpCommands.java b/src/utils/HelpCommands.java index 1440b72..b1c28a2 100644 --- a/src/utils/HelpCommands.java +++ b/src/utils/HelpCommands.java @@ -285,6 +285,14 @@ public static Queue buildQueue(int n, int max) { return queue; } + public static Queue buildQueue(int... values) { + Queue queue = new Queue<>(); + for (int value : values) { + queue.insert(value); + } + return queue; + } + /** * @param queue * @return the length of the queue