Created
April 29, 2015 07:54
-
-
Save 3c7/41aa50df71166526b7bc to your computer and use it in GitHub Desktop.
Algorithmen und Datenstrukturen Übung 4 Aufgabe 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 28.04.2015. | |
*/ | |
public class Feld<T> { | |
private T[] feld; | |
public Feld(int anzahl) { | |
@SuppressWarnings("unchecked") | |
T[] f = (T[])new Object[anzahl]; | |
feld = f; | |
} | |
public int size() { | |
return feld.length; | |
} | |
public T get(int i) { | |
return feld[i]; | |
} | |
public T set(int i, T e) { | |
T result = feld[i]; | |
feld[i] = e; | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 28.04.2015. | |
*/ | |
public class Paar<T> { | |
private T first, second; | |
public Paar(T f, T s) { | |
this.first = f; | |
this.second = s; | |
} | |
public void swap() { | |
T tmp; | |
tmp = this.first; | |
this.first = this.second; | |
this.second = tmp; | |
} | |
public T first() { | |
return this.first; | |
} | |
public T second() { | |
return this.second; | |
} | |
public String toString() { | |
return "(" + this.first() + "," + this.second() + ")"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nils on 28.04.2015. | |
*/ | |
@SuppressWarnings("unchecked") | |
public class PaarFeld<T> { | |
private Feld<T> a, b; | |
private int length; | |
public PaarFeld(Feld<T> a, Feld<T> b) { | |
this.length = (a.size() < b.size()) ? a.size() : b.size(); | |
this.a = a; | |
this.b = b; | |
} | |
public Paar<T> get(int i) throws ArrayIndexOutOfBoundsException { | |
if(i < length) { | |
return new Paar<T>(a.get(i), b.get(i)); | |
} else { | |
throw new ArrayIndexOutOfBoundsException(); | |
} | |
} | |
public Paar<T> set(int i, Paar<T> a) { | |
return new Paar<T>(this.a.set(i, a.first()), this.b.set(i, a.second())); | |
} | |
public int size() { | |
return this.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment