Compare commits

...

10 Commits

58 changed files with 1572 additions and 62 deletions

6
.gitattributes vendored Normal file
View File

@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
/*.iml
/.idea
/out
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build

View File

@ -14,7 +14,7 @@ Dann einfach alle TODOs abarbeiten.
## Sequenzen
Für jede Datenstruktur, die Sequenzen darstellen,
sollte das Interface [`SequenceProcessor`](src/aud/exam/prep/SequenceProcessor.java)
sollte das Interface [`SequenceProcessor`](src/main/java/aud/exam/prep/SequenceProcessor.java)
einmal iterativ und einmal rekursiv implementiert werden.
Jede fast Methode in `SequenceProcessor` stellt eine Aufgabe dar,
@ -38,4 +38,4 @@ durch eine Sequenz `s`.
<https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#equals-java.lang.Object-java.lang.Object->
1. Neues Array vom Typ `T` erstellen:
[`Arrays.newArray(size)`](src/aud/exam/prep/array/Arrays.java)
[`Arrays.newArray(size)`](src/main/java/aud/exam/prep/array/Arrays.java)

32
build.gradle.kts Normal file
View File

@ -0,0 +1,32 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.4.1/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}
application {
// Define the main class for the application.
mainClass.set("aud.exam.prep.Main")
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
gradlew vendored Executable file
View File

@ -0,0 +1,234 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

89
gradlew.bat vendored Normal file
View File

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

10
settings.gradle.kts Normal file
View File

@ -0,0 +1,10 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/7.4.1/userguide/multi_project_builds.html
*/
rootProject.name = "aud-exam-prep"

View File

@ -1,7 +0,0 @@
package aud.exam.prep.list;
public class DoubleListItem<T> {
public T key;
public DoubleListItem<T> next;
public DoubleListItem<T> prev;
}

View File

@ -1,6 +0,0 @@
package aud.exam.prep.list;
public class SingleListItem<T> {
public T key;
public SingleListItem<T> next;
}

View File

@ -1,36 +0,0 @@
package aud.exam.prep.tree;
abstract class OrderedBinaryTreeNodeProcessor<V> implements OrderedTreeProcessor<V, BinaryTreeNode<V>> {
@Override
public BinaryTreeNode<V> newEmptyTree() {
return null;
}
@Override
public Iterable<V> iterate(BinaryTreeNode<V> tree) {
return () ->
new BinaryTreeIterator<>(tree);
}
@Override
public void print(BinaryTreeNode<V> tree) {
printRec(tree, 0);
}
private void printRec(BinaryTreeNode<V> tree, int indent) {
if (tree == null) {
System.out.println("- *");
return;
}
System.out.println("-> " + tree.key);
System.out.print(" |".repeat(indent));
System.out.print(" L");
printRec(tree.left, indent + 1);
System.out.print(" |".repeat(indent));
System.out.print(" L");
printRec(tree.right, indent + 1);
}
}

View File

@ -0,0 +1,11 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package aud.exam.prep;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@ -0,0 +1,17 @@
package aud.exam.prep.list;
public class DoubleListItem<T> implements ListItem<T> {
public T key;
public DoubleListItem<T> prev;
public DoubleListItem<T> next;
@Override
public T head() {
return key;
}
@Override
public ListItem<T> tail() {
return next;
}
}

View File

@ -0,0 +1,12 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessor;
abstract class DoubleListItemProcessor<T> implements SequenceProcessor<T, DoubleListItem<T>> {
@Override
public Iterable<T> iterate(DoubleListItem<T> list) {
return () ->
new ListItemIterator<>(list);
}
}

View File

@ -0,0 +1,194 @@
package aud.exam.prep.list;
import aud.exam.prep.Pair;
import java.util.Comparator;
public class IterativeDoubleListItemProcessor<T> extends DoubleListItemProcessor<T> {
@Override
public boolean find(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean findBinary(DoubleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean override(DoubleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAll(DoubleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAt(DoubleListItem<T> list, T to, int index) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void insertInOrder(DoubleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean remove(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean removeAll(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isAscending(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T max(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T secondMax(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLessOrEqual(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLess(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isLexSmaller(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void exchangePairs(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void rotateTriples(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeEverySecond(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void doubleAllKeys(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> rotateRight(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> rotateLeft(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeDuplicates(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> invert(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> clone(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> alternate(DoubleListItem<T> a, DoubleListItem<T> b) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> merge(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideAlternating(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideAlternatingByRuns(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideByPivot(DoubleListItem<T> list, T pivot, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean check(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> create(Iterable<T> iterable) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Iterable<T> iterate(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
}

View File

@ -0,0 +1,194 @@
package aud.exam.prep.list;
import aud.exam.prep.Pair;
import java.util.Comparator;
public class IterativeSingleListItemProcessor<T> extends SingleListItemProcessor<T> {
@Override
public boolean find(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean findBinary(SingleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean override(SingleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAll(SingleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAt(SingleListItem<T> list, T to, int index) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void insertInOrder(SingleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean remove(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean removeAll(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isAscending(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T max(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T secondMax(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLessOrEqual(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLess(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isLexSmaller(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void exchangePairs(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void rotateTriples(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeEverySecond(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void doubleAllKeys(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> rotateRight(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> rotateLeft(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeDuplicates(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> invert(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> clone(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> alternate(SingleListItem<T> a, SingleListItem<T> b) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> merge(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideAlternating(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideAlternatingByRuns(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideByPivot(SingleListItem<T> list, T pivot, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean check(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> create(Iterable<T> iterable) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Iterable<T> iterate(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
}

View File

@ -0,0 +1,8 @@
package aud.exam.prep.list;
public interface ListItem<T> {
T head();
ListItem<T> tail();
}

View File

@ -0,0 +1,24 @@
package aud.exam.prep.list;
import java.util.Iterator;
public class ListItemIterator<T> implements Iterator<T> {
private ListItem<T> current;
public ListItemIterator(ListItem<T> current) {
this.current = current;
}
@Override
public boolean hasNext() {
return current != null;
}
@Override
public T next() {
T t = current.head();
current = current.tail();
return t;
}
}

View File

@ -0,0 +1,253 @@
package aud.exam.prep.list;
import aud.exam.prep.Pair;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
public class RecursiveDoubleListItemProcessor<T> extends DoubleListItemProcessor<T> {
@Override
public boolean find(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean findBinary(DoubleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean override(DoubleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAll(DoubleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAt(DoubleListItem<T> list, T to, int index) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void insertInOrder(DoubleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean remove(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean removeAll(DoubleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isAscending(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T max(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T secondMax(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLessOrEqual(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLess(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isLexSmaller(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void exchangePairs(DoubleListItem<T> list) {
if (list == null || list.next == null || list.next.next == null) {
return;
}
var next = list.next;
var nextNext = next.next;
var rest = nextNext.next;
list.next = nextNext;
nextNext.prev = list;
nextNext.next = next;
next.prev = nextNext;
next.next = rest;
if (rest != null) {
rest.prev = next;
}
exchangePairs(list.next.next);
}
@Override
public void rotateTriples(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeEverySecond(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void doubleAllKeys(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> rotateRight(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> rotateLeft(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeDuplicates(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> invert(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> clone(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> alternate(DoubleListItem<T> a, DoubleListItem<T> b) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public DoubleListItem<T> merge(DoubleListItem<T> a, DoubleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideAlternating(DoubleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideAlternatingByRuns(DoubleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<DoubleListItem<T>, DoubleListItem<T>> divideByPivot(DoubleListItem<T> list, T pivot, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean check(DoubleListItem<T> list) {
return checkRec(list, new HashSet<>(), null);
}
private boolean checkRec(DoubleListItem<T> list, HashSet<DoubleListItem<T>> seen, DoubleListItem<T> prev) {
if (list == null) {
if (seen.isEmpty()) {
return true;
}
if (prev == null) {
return true;
}
return prev.next == null;
}
if (list.prev != prev) {
return false;
}
if (prev != null && prev.next != list) {
return false;
}
if (list.key == null) {
return false;
}
if (seen.contains(list)) {
return false;
}
seen.add(list);
return checkRec(list.next, seen, list);
}
@Override
public DoubleListItem<T> create(Iterable<T> iterable) {
var iter = iterable.iterator();
return createRec(iter, null);
}
private DoubleListItem<T> createRec(Iterator<T> iter, DoubleListItem<T> prev) {
if (!iter.hasNext()) {
return null;
}
var item = new DoubleListItem<T>();
item.key = iter.next();
item.next = createRec(iter, item);
item.prev = prev;
return item;
}
}

View File

@ -0,0 +1,194 @@
package aud.exam.prep.list;
import aud.exam.prep.Pair;
import java.util.Comparator;
public class RecursiveSingleListItemProcessor<T> extends SingleListItemProcessor<T> {
@Override
public boolean find(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean findBinary(SingleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean override(SingleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAll(SingleListItem<T> list, T from, T to) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean overrideAt(SingleListItem<T> list, T to, int index) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void insertInOrder(SingleListItem<T> list, T t, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean remove(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean removeAll(SingleListItem<T> list, T t) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isAscending(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T max(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public T secondMax(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLessOrEqual(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isItemWiseLess(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean isLexSmaller(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void exchangePairs(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void rotateTriples(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeEverySecond(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void doubleAllKeys(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> rotateRight(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> rotateLeft(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public void removeDuplicates(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> invert(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> clone(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> alternate(SingleListItem<T> a, SingleListItem<T> b) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> merge(SingleListItem<T> a, SingleListItem<T> b, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideAlternating(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideAlternatingByRuns(SingleListItem<T> list, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Pair<SingleListItem<T>, SingleListItem<T>> divideByPivot(SingleListItem<T> list, T pivot, Comparator<T> cmp) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public boolean check(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public SingleListItem<T> create(Iterable<T> iterable) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
@Override
public Iterable<T> iterate(SingleListItem<T> list) {
// TODO: Your training
throw new RuntimeException("unimplemented");
}
}

View File

@ -0,0 +1,17 @@
package aud.exam.prep.list;
public class SingleListItem<T> implements ListItem<T> {
public T key;
public SingleListItem<T> next;
@Override
public T head() {
return key;
}
@Override
public ListItem<T> tail() {
return next;
}
}

View File

@ -0,0 +1,6 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessor;
abstract class SingleListItemProcessor<T> implements SequenceProcessor<T, SingleListItem<T>> {
}

View File

@ -0,0 +1,15 @@
package aud.exam.prep.tree;
abstract class OrderedBinaryTreeNodeProcessor<V> implements OrderedTreeProcessor<V, BinaryTreeNode<V>> {
@Override
public BinaryTreeNode<V> newEmptyTree() {
return null;
}
@Override
public Iterable<V> iterate(BinaryTreeNode<V> tree) {
return () ->
new BinaryTreeIterator<>(tree);
}
}

View File

@ -3,6 +3,7 @@ package aud.exam.prep.tree;
import aud.exam.prep.Pointer;
import java.util.Comparator;
import java.util.function.Predicate;
/**
* Instances of this interface can work with any "valid" tree of type <code>T</code>.
@ -27,6 +28,8 @@ public interface OrderedTreeProcessor<V, T> {
boolean removeAll(Pointer<T> t, V v, Comparator<V> cmp);
T removeIf(T t, Predicate<V> pred);
V max(T t);
V secondMax(T t);
@ -43,7 +46,7 @@ public interface OrderedTreeProcessor<V, T> {
T leftmostNodeInRightSubtree(T t);
T invert(T t);
void invert(T t);
T clone(T t);

View File

@ -3,6 +3,7 @@ package aud.exam.prep.tree;
import aud.exam.prep.Pointer;
import java.util.Comparator;
import java.util.function.Predicate;
public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTreeNodeProcessor<V> {
@ -221,6 +222,42 @@ public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTre
return removeAllWithCountRec(node.right, v, cmp, node, true);
}
@Override
public BinaryTreeNode<V> removeIf(BinaryTreeNode<V> root, Predicate<V> pred) {
if (root == null) {
return null;
}
root.left = removeIf(root.left, pred);
root.right = removeIf(root.right, pred);
if (pred.test(root.key)) {
if (root.left == null) {
return root.right;
} else if (root.right == null) {
return root.left;
} else {
root.key = removeRightMostNode(root.left, root, false);
}
}
return root;
}
V removeRightMostNode(BinaryTreeNode<V> node, BinaryTreeNode<V> prev, boolean right) {
if (node.right != null) {
return removeRightMostNode(node.right, node, true);
}
if (right) {
prev.right = node.left;
} else {
prev.left = node.left;
}
return node.key;
}
@Override
public V max(BinaryTreeNode<V> tree) {
if (tree == null) {
@ -273,10 +310,7 @@ public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTre
@Override
public boolean isBalanced(BinaryTreeNode<V> tree) {
if (tree == null) {
return true;
}
return false;
return tree == null;
}
@Override
@ -300,13 +334,31 @@ public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTre
}
@Override
public BinaryTreeNode<V> invert(BinaryTreeNode<V> tree) {
return null;
public void invert(BinaryTreeNode<V> tree) {
if (tree == null) {
return;
}
invert(tree.left);
invert(tree.right);
var t = tree.left;
tree.left = tree.right;
tree.right = t;
}
@Override
public BinaryTreeNode<V> clone(BinaryTreeNode<V> tree) {
return null;
if (tree == null) {
return null;
}
var t = new BinaryTreeNode<V>();
t.left = clone(tree.left);
t.right = clone(tree.right);
t.key = tree.key;
return t;
}
@Override
@ -331,4 +383,26 @@ public class RecursiveOrderedBinaryTreeNodeProcessor<V> extends OrderedBinaryTre
return true;
}
@Override
public void print(BinaryTreeNode<V> tree) {
printRec(tree, 0);
}
private void printRec(BinaryTreeNode<V> tree, int indent) {
if (tree == null) {
System.out.println("- *");
return;
}
System.out.println("-> " + tree.key);
System.out.print(" |".repeat(indent));
System.out.print(" L");
printRec(tree.left, indent + 1);
System.out.print(" |".repeat(indent));
System.out.print(" L");
printRec(tree.right, indent + 1);
}
}

View File

@ -10,7 +10,7 @@ import java.util.stream.Stream;
public class DoubleLatinProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) throws Exception {
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream
.generate(() ->
Arguments.of(randomLatin(), randomLatin()))

View File

@ -0,0 +1,51 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessor;
import aud.exam.prep.SequenceProcessorTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
abstract class DoubleListItemProcessorTest extends SequenceProcessorTest<DoubleListItem<Integer>> {
protected DoubleListItemProcessorTest(SequenceProcessor<Integer, DoubleListItem<Integer>> processor) {
super(processor);
}
@Test
void testThat_checkOfNullIsTrue() {
assertTrue(processor.check(null));
}
@Test
void testThat_checkOfNoKeyIsFalse() {
var item = new DoubleListItem<Integer>();
assertFalse(processor.check(item));
}
@Test
void testThat_checkOfNoPrevOfNextIsFalse() {
var item = new DoubleListItem<Integer>();
item.key = 1;
item.next = new DoubleListItem<>();
item.next.key = 1;
assertFalse(processor.check(item));
}
@Test
void testThat_checkOfCircleIsFalse() {
var item = new DoubleListItem<Integer>();
item.next = item;
assertFalse(processor.check(item));
}
@Test
void testThat_checkPrevNextNotMatchingIsFalse() {
var item = new DoubleListItem<Integer>();
item.next = new DoubleListItem<>();
item.next.prev = new DoubleListItem<>();
assertFalse(processor.check(item));
}
}

View File

@ -0,0 +1,10 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessorTest;
class IterativeDoubleListItemProcessorTest extends SequenceProcessorTest<DoubleListItem<Integer>> {
protected IterativeDoubleListItemProcessorTest() {
super(new IterativeDoubleListItemProcessor<>());
}
}

View File

@ -0,0 +1,10 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessorTest;
class IterativeSingleListItemProcessorTest extends SequenceProcessorTest<SingleListItem<Integer>> {
protected IterativeSingleListItemProcessorTest() {
super(new IterativeSingleListItemProcessor<>());
}
}

View File

@ -0,0 +1,8 @@
package aud.exam.prep.list;
public class RecursiveDoubleListItemProcessorTest extends DoubleListItemProcessorTest {
protected RecursiveDoubleListItemProcessorTest() {
super(new RecursiveDoubleListItemProcessor<>());
}
}

View File

@ -0,0 +1,10 @@
package aud.exam.prep.list;
import aud.exam.prep.SequenceProcessorTest;
class RecursiveSingleListItemProcessorTest extends SequenceProcessorTest<SingleListItem<Integer>> {
protected RecursiveSingleListItemProcessorTest() {
super(new RecursiveSingleListItemProcessor<>());
}
}

View File

@ -10,6 +10,9 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static aud.exam.prep.Tests.CMP;
import static org.junit.jupiter.api.Assertions.*;
@ -69,7 +72,7 @@ public abstract class OrderedTreeProcessorTest<T> {
assertIterableEquals(list, processor.iterate(t));
}
private T asTree(List<Integer> list) {
protected T asTree(List<Integer> list) {
T t = processor.newEmptyTree();
for (var n : list) {
@ -168,6 +171,46 @@ public abstract class OrderedTreeProcessorTest<T> {
}
}
@ParameterizedTest
@ArgumentsSource(ListProvider.class)
void testThat_removeIfWorks(List<Integer> list) {
T t = asTree(list);
list.sort(CMP);
for (var toRemove : getRemovals(list)) {
Predicate<Integer> pred = n ->
Objects.equals(n, toRemove);
list.removeIf(pred);
t = processor.removeIf(t, pred);
assertTrue(processor.check(t, CMP));
assertIterableEquals(list, processor.iterate(t));
}
}
List<Integer> getRemovals(List<Integer> list) {
var start = -100 + list
.stream()
.min(CMP)
.orElse(0);
var end = 100 + list
.stream()
.max(CMP)
.orElse(0);
var removals = IntStream
.rangeClosed(start, end)
.boxed()
.collect(Collectors.toList());
Collections.shuffle(removals, Tests.RANDOM);
return removals;
}
@ParameterizedTest
@ArgumentsSource(ListProvider.class)
void printATree(List<Integer> list) {
@ -243,4 +286,28 @@ public abstract class OrderedTreeProcessorTest<T> {
assertIterableEquals(list, processor.iterate(t));
}
}
@ParameterizedTest
@ArgumentsSource(ListProvider.class)
void testThat_invertWorks(List<Integer> list) {
T t = asTree(list);
processor.invert(t);
var cmp = CMP.reversed();
assertTrue(processor.check(t, cmp));
list.sort(cmp);
assertIterableEquals(list, processor.iterate(t));
}
@ParameterizedTest
@ArgumentsSource(ListProvider.class)
void testThat_cloneWorks(List<Integer> list) {
T t = asTree(list);
t = processor.clone(t);
assertTrue(processor.check(t, CMP));
list.sort(CMP);
assertIterableEquals(list, processor.iterate(t));
}
}