summaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorBen Culkin <scorpress@gmail.com>2022-09-27 19:09:11 -0400
committerBen Culkin <scorpress@gmail.com>2022-09-27 19:09:11 -0400
commit2442e05e638a61dd1bfbd6b95cb3544b6a327af9 (patch)
tree7d332d1b84bc9338d38664de64c166f1641f3fe9 /src/example
parent2d5c3288134f19088941c980e852521e9838db56 (diff)
GPLize project
Finally deciding to move things into a proper license; which I can do since I've never accepted (or had :( ) a pull request from another person
Diffstat (limited to 'src/example')
-rw-r--r--src/example/java/bjc/funcdata/bst/BinarySearchTreeExample.java43
-rw-r--r--src/example/java/bjc/functypes/FixpointExample.java27
2 files changed, 47 insertions, 23 deletions
diff --git a/src/example/java/bjc/funcdata/bst/BinarySearchTreeExample.java b/src/example/java/bjc/funcdata/bst/BinarySearchTreeExample.java
index 258b17d..857b5be 100644
--- a/src/example/java/bjc/funcdata/bst/BinarySearchTreeExample.java
+++ b/src/example/java/bjc/funcdata/bst/BinarySearchTreeExample.java
@@ -1,3 +1,20 @@
+/*
+ * esodata - data structures and other things, of varying utility
+ * Copyright 2022, Ben Culkin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
package bjc.funcdata.bst;
import java.io.*;
@@ -10,10 +27,8 @@ import java.util.*;
*
*/
public class BinarySearchTreeExample {
- private static void display(final BinarySearchTree<Character> tree,
- final Scanner input, PrintStream output) {
- output.print(
- "What order would you like the tree to be printed in (m for options): ");
+ private static void display(final BinarySearchTree<Character> tree, final Scanner input, PrintStream output) {
+ output.print("What order would you like the tree to be printed in (m for options): ");
char command;
while (true) {
@@ -23,12 +38,9 @@ public class BinarySearchTreeExample {
switch (command) {
case 'm':
System.out.println("Possible tree printing methods: ");
- System.out.println(
- "\tp: Preorder printing (print parent first, then left & right).");
- System.out.println(
- "\ti: Inorder printing (print left first, then parent & right).");
- System.out.println(
- "\to: Postorder printing (print left first, then right & parent).");
+ System.out.println("\tp: Preorder printing (print parent first, then left & right).");
+ System.out.println("\ti: Inorder printing (print left first, then parent & right).");
+ System.out.println("\to: Postorder printing (print left first, then right & parent).");
break;
case 'p':
method = TreeLinearizationMethod.PREORDER;
@@ -52,16 +64,14 @@ public class BinarySearchTreeExample {
return;
}
- System.out.print(
- "What order would you like the tree to be printed in (m for options): ");
+ System.out.print("What order would you like the tree to be printed in (m for options): ");
}
}
/**
* Main method of class
*
- * @param args
- * Unused CLI args
+ * @param args Unused CLI args
*/
public static void main(final String[] args) {
try (Scanner input = new Scanner(System.in)) {
@@ -71,11 +81,10 @@ public class BinarySearchTreeExample {
private static void runExample(final Scanner input, OutputStream outpt) {
System.out.println("Binary Tree Constructor/Searcher");
- final BinarySearchTree<Character> tree
- = new BinarySearchTree<>((o1, o2) -> o1 - o2);
+ final BinarySearchTree<Character> tree = new BinarySearchTree<>((o1, o2) -> o1 - o2);
PrintStream output = new PrintStream(outpt);
-
+
char command = ' ';
while (command != 'e') {
output.print("Enter a command (m for help): ");
diff --git a/src/example/java/bjc/functypes/FixpointExample.java b/src/example/java/bjc/functypes/FixpointExample.java
index 71dab4a..d64daf7 100644
--- a/src/example/java/bjc/functypes/FixpointExample.java
+++ b/src/example/java/bjc/functypes/FixpointExample.java
@@ -1,3 +1,20 @@
+/*
+ * esodata - Data structures of varying utility
+ * Copyright 2022, Ben Culkin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
package bjc.functypes;
import static bjc.functypes.Combinators.*;
@@ -10,18 +27,16 @@ import java.util.function.*;
* @author Ben Culkin
*
*/
-public class FixpointExample
-{
+public class FixpointExample {
/**
* Main method.
*
* @param args Unused CLI args.
*/
public static void main(String[] args) {
- Function<Integer, Integer> factorial = Fixpoints.fix((input, self) -> {
- if (input <= 1) return 1;
- else return input * self.apply(input - 1);
- });
+ Function<Integer,
+ Integer> factorial = Fixpoints.fix(
+ (input, self) -> input <= 1 ? 1 : input * self.apply(input - 1));
times(10, andThen(factorial::apply, System.out::println));
}