Studieren Sie den zur Aufgabe gehörenden Lehrbrief und lösen Sie die Aufgaben darin. Testen Sie ihre Lösungen zunächst am besten interaktiv in der JShell.
package name.panitz.util;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Consumer;
import java.util.Comparator;
public class AL<E> {
private int size = 0;
private Object[]store = new Object[10];
public boolean isEmpty(){return size==0;}
public int length(){
return size;
}
public E get(int i){
if (i>=size||i<0) throw new IndexOutOfBoundsException();
return (E)store[i];
}
public E head(){return get(0);}
public static <E>AL<E> nil(){return new AL<>();}
public void add(E e){
if (size>=store.length) enlargeStore();
store[size++] = e;
}
private void enlargeStore(){
Object[]newStore = new Object[store.length+10];
for (int i=0;i<size;i++) newStore[i]=store[i];
store=newStore;
}
public static <E>AL<E> of(E...es){
AL<E> r = nil();
for (var e:es) r.add(e);
return r;
}
@Override public String toString(){
StringBuffer result = new StringBuffer("[");
boolean first = true;
for (var i=0;i<size;i++){
if (first) first = false;else result.append(", ");
result.append(store[i]);
}
result.append("]");
return result.toString();
}
@Override public boolean equals(Object o){
if (o.getClass()!=AL.class) return false;
var that = (AL<E>)o;
if (this.length()!=that.length()) return false;
for (int i=0;i<size;i++){
if (!this.get(i).equals(that.get(i)))return false;
}
return true;
}
public E last(){
return null; /*ToDo*/
}
public AL<E> append(AL<E> that){
AL<E> rs = nil();
return rs; /*ToDo*/
}
public void addAll(AL<E> that){
/*ToDo*/
}
public AL<E> drop(int i){
AL<E> rs = nil();
return rs; /*ToDo*/
}
public AL<E> tail(){return drop(1);}
public AL<E> take(int i){
AL<E> rs = nil();
return rs; /*ToDo*/
}
public AL<E> sublist(int from, int length) {
return nil(); /*ToDo*/
}
public AL<E> reverse(){
return nil(); /*ToDo*/
}
public AL<E> intersperse(E e){
return nil(); /*ToDo*/
}
public boolean isPrefixOf(AL<E> that){
return false; /*ToDo*/
}
public boolean isSuffixOf(AL<E> that){
return false; /*ToDo*/
}
public boolean isInfixOf(AL<E> that){
return false; /*ToDo*/
}
public AL<E> rotate(){
return nil(); /*ToDo*/
}
public AL<AL<E>> tails(){
return of(nil()); /*ToDo*/
}
public void forEach(Consumer<? super E> con) {
/*ToDo*/
}
public boolean containsWith(Predicate< ? super E> p) {
return false; /*ToDo*/
}
public boolean contains(E el) {
return false; /*ToDo*/
}
public AL<E> dropWhile(Predicate< ? super E> p){
return nil(); /*ToDo*/
}
public AL<E> takeWhile(Predicate< ? super E> p){
return nil(); /*ToDo*/
}
public AL<E> filter(Predicate<? super E> p){
return nil(); /*ToDo*/
}
public <R> AL<R> map(Function<? super E, ? extends R> f){
return nil(); /*ToDo*/
}
static public record Pair<A,B>(A fst,B snd){
@Override public String toString(){return "("+fst()+", "+snd()+")";}
}
public <B> AL<Pair<E,B>> zip(AL<B> that){
return nil(); /*ToDo*/
}
public Pair<AL<E>,AL<E>> span(Predicate<? super E> p){
return new Pair<>(nil(),nil()); /*ToDo*/
}
public Pair<AL<E>,AL<E>> partition(Predicate<? super E> p){
return new Pair<>(nil(),nil()); /*ToDo*/
}
public boolean isSorted(Comparator<? super E> cmp){
return false; /*ToDo*/
}
public AL<E> qsort(Comparator<? super E> cmp){
return nil(); /*ToDo*/
}
}