Update
parent
4a0a222452
commit
0d0d1f3f59
Binary file not shown.
|
@ -0,0 +1,17 @@
|
||||||
|
package DynamicTree;
|
||||||
|
|
||||||
|
public class DynamicTree <T extends Comparable <T>> {
|
||||||
|
|
||||||
|
public void add(T e) {
|
||||||
|
if(root == null) {
|
||||||
|
root = new TreeElement<T>(e);
|
||||||
|
} else {
|
||||||
|
if(e.compareTo(root.value) < 0 )
|
||||||
|
root.left = new TreeElement <T> (e);
|
||||||
|
|
||||||
|
else
|
||||||
|
root.right = new TreeElement <T>(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,81 @@
|
||||||
|
package Indexverwaltung;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
|
||||||
|
public class Datei {
|
||||||
|
private int aktuell;
|
||||||
|
private String dateiname = "Stammdatei.txt";
|
||||||
|
private int SATZLAENGE = 100;
|
||||||
|
private RandomAccessFile eineStammDatei;
|
||||||
|
|
||||||
|
public Datei() { }
|
||||||
|
|
||||||
|
public Datei(int satzlaenge)
|
||||||
|
{
|
||||||
|
SATZLAENGE = satzlaenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void speichereSatz(String satz, int index) throws IOException
|
||||||
|
{
|
||||||
|
positioniereAufSatz(index);
|
||||||
|
writeFixedString(satz, SATZLAENGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String leseSatz(int index) throws IOException
|
||||||
|
{
|
||||||
|
positioniereAufSatz(index);
|
||||||
|
|
||||||
|
return readFixedString(SATZLAENGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void oeffneDatei(String name) throws IOException
|
||||||
|
{
|
||||||
|
if(!name.isBlank())
|
||||||
|
dateiname = name;
|
||||||
|
|
||||||
|
eineStammDatei = new RandomAccessFile(dateiname, "rw");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void schliesseDatei() throws IOException
|
||||||
|
{
|
||||||
|
eineStammDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int gibAnzahlDatensaetze() throws IOException
|
||||||
|
{
|
||||||
|
return (int) (eineStammDatei.length() / SATZLAENGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void positioniereAufSatz(int index) throws IOException
|
||||||
|
{
|
||||||
|
if(index * SATZLAENGE * Character.BYTES != aktuell)
|
||||||
|
{
|
||||||
|
aktuell = index * SATZLAENGE * Character.BYTES;
|
||||||
|
eineStammDatei.seek(aktuell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readFixedString(int laenge) throws IOException
|
||||||
|
{
|
||||||
|
StringBuffer satz = new StringBuffer();
|
||||||
|
|
||||||
|
while(laenge-- > 0)
|
||||||
|
satz.append(eineStammDatei.readChar());
|
||||||
|
|
||||||
|
return satz.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFixedString(String einDatensatz, int laenge) throws IOException
|
||||||
|
{
|
||||||
|
StringBuffer sb = new StringBuffer(einDatensatz);
|
||||||
|
|
||||||
|
while(sb.length() != laenge)
|
||||||
|
sb.append('\0');
|
||||||
|
|
||||||
|
for(int index = 0; index < laenge; index++) {
|
||||||
|
|
||||||
|
eineStammDatei.writeChar(sb.charAt(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package Indexverwaltung;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class Index {
|
||||||
|
// Attribute
|
||||||
|
private final int MAX = 10;
|
||||||
|
private String dateiname = "Indexdatei.txt";
|
||||||
|
private int indextabelle[]; // 0 .. MAX-1
|
||||||
|
private RandomAccessFile eineIndexDatei;
|
||||||
|
|
||||||
|
// Konstruktor
|
||||||
|
public Index() {
|
||||||
|
|
||||||
|
indextabelle = new int[MAX];
|
||||||
|
// Initialisierung der indextabelle
|
||||||
|
for (int i = 0; i < MAX; i++)
|
||||||
|
indextabelle[i] = -1;
|
||||||
|
// Kein Datensatz zu Schluessel vorhanden
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methoden
|
||||||
|
public void erzeugeEintrag(int schluessel, int index) throws IOException {
|
||||||
|
/**
|
||||||
|
* Speichert zu einen Schluessel den zugehoerigen Datensatz-Index in der
|
||||||
|
* indextabelle
|
||||||
|
*/
|
||||||
|
if (schluessel < MAX)
|
||||||
|
indextabelle[schluessel] = index;
|
||||||
|
// Aktualisieren der Indexdatei,
|
||||||
|
// d. h. Abspeichern der Datei
|
||||||
|
aktualisiereIndexDatei(schluessel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int gibIndexZuSchluessel(int schluessel) throws InvalidIndexException {
|
||||||
|
/*
|
||||||
|
* // Gibt zu dem Schluessel den gefundenen // Datensatz-Index zurueck
|
||||||
|
* if(schluessel < MAX) return indextabelle[schluessel]; // oder -1, wenn
|
||||||
|
* Schluessel zu gross ist else return -1;
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (schluessel >= MAX || indextabelle[schluessel] == -1)
|
||||||
|
throw new InvalidIndexException(schluessel);
|
||||||
|
|
||||||
|
return indextabelle[schluessel];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ladeIndexDatei() throws IOException {
|
||||||
|
/**
|
||||||
|
* Liest die Indextabelle vollstaendig aus einer Datei Dies geschieht nur beim
|
||||||
|
* Start des Programms
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "r");
|
||||||
|
int index;
|
||||||
|
for (int schluessel = 0; schluessel < MAX; schluessel++) {
|
||||||
|
index = eineIndexDatei.readInt();
|
||||||
|
indextabelle[schluessel] = index;
|
||||||
|
}
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void speichereIndexDatei() throws IOException {
|
||||||
|
/**
|
||||||
|
* Speichert die Indextabelle vollstaendig in einer Datei Dies geschieht beim
|
||||||
|
* Beenden des Programs
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "rw");
|
||||||
|
for (int schluessel = 0; schluessel < MAX; schluessel++)
|
||||||
|
eineIndexDatei.writeInt(indextabelle[schluessel]);
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void aktualisiereIndexDatei(int schluessel) throws IOException {
|
||||||
|
/**
|
||||||
|
* Aktualisiert die indextabelle in der Indexdatei Dies geschieht beim
|
||||||
|
* Hinzufuegen eines neuen Indexes oder Aendern eines alten Indexes
|
||||||
|
*/
|
||||||
|
eineIndexDatei = new RandomAccessFile(dateiname, "rw");
|
||||||
|
// eine int-Zahl belegt 4 Bytes
|
||||||
|
eineIndexDatei.seek((long) (schluessel * 4));
|
||||||
|
eineIndexDatei.writeInt(indextabelle[schluessel]);
|
||||||
|
eineIndexDatei.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zum Testen
|
||||||
|
public void gibIndextabelleAus() {
|
||||||
|
int schluessel = 0;
|
||||||
|
for (int element : indextabelle) {
|
||||||
|
System.out.println(schluessel + " " + element);
|
||||||
|
schluessel++;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package Indexverwaltung;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class IndexUI {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
Index indexDatei = new Index();
|
||||||
|
Datei stammDatei = new Datei();
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
try {
|
||||||
|
indexDatei.ladeIndexDatei();
|
||||||
|
}
|
||||||
|
catch(IOException e)
|
||||||
|
{
|
||||||
|
System.err.println("INFO - Dateien nicht vorhanden - Erzeuge Beispiel!");
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
try {
|
||||||
|
stammDatei.oeffneDatei("stammdatei.txt");
|
||||||
|
|
||||||
|
indexDatei.erzeugeEintrag(6, idx);
|
||||||
|
stammDatei.speichereSatz("Satz 1", idx);
|
||||||
|
|
||||||
|
idx++;
|
||||||
|
indexDatei.erzeugeEintrag(1, idx);
|
||||||
|
stammDatei.speichereSatz("Satz 2", idx);
|
||||||
|
|
||||||
|
idx++;
|
||||||
|
indexDatei.erzeugeEintrag(3, idx);
|
||||||
|
stammDatei.speichereSatz("Satz 3", idx);
|
||||||
|
|
||||||
|
idx++;
|
||||||
|
indexDatei.speichereIndexDatei();
|
||||||
|
stammDatei.schliesseDatei();
|
||||||
|
|
||||||
|
} catch (IOException ee) {
|
||||||
|
ee.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
indexDatei.gibIndextabelleAus();
|
||||||
|
|
||||||
|
try {
|
||||||
|
stammDatei.oeffneDatei("stammdatei.txt");
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
System.out.print("Bitte geben Sie einen Schluessel ein:");
|
||||||
|
String schluessel = sc.nextLine();
|
||||||
|
|
||||||
|
if(schluessel.isEmpty())
|
||||||
|
break;
|
||||||
|
|
||||||
|
try {
|
||||||
|
int index = indexDatei.gibIndexZuSchluessel(Integer.parseInt(schluessel));
|
||||||
|
|
||||||
|
String satz = stammDatei.leseSatz(index);
|
||||||
|
|
||||||
|
System.out.println("Der zu " + schluessel + " gewuenschte Satz lautet: ==> " + satz + " <==");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvalidIndexException e) {
|
||||||
|
System.err.println("\n==> Zugriff auf nicht vorhandenen Schluessel: " + e.gibSchluessel() + " <==");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (NumberFormatException e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
|
||||||
|
indexDatei.speichereIndexDatei();
|
||||||
|
|
||||||
|
stammDatei.schliesseDatei();
|
||||||
|
|
||||||
|
System.err.println("Dateien geschlossen!");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Programm beendet!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package Indexverwaltung;
|
||||||
|
|
||||||
|
public class InvalidIndexException extends Exception {
|
||||||
|
private int schluessel;
|
||||||
|
|
||||||
|
public InvalidIndexException(int s) {
|
||||||
|
super("Access to Unknown Index");
|
||||||
|
schluessel = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidIndexException(int s, String fehlermeldung) {
|
||||||
|
super(fehlermeldung);
|
||||||
|
schluessel = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int gibSchluessel() {
|
||||||
|
return schluessel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void neueException() throws Exception {
|
||||||
|
throw new Exception("Index überschreitet Maximum");
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,15 +3,15 @@ package Uebung2;
|
||||||
public class Unterzaehler extends Zaehler {
|
public class Unterzaehler extends Zaehler {
|
||||||
|
|
||||||
private int unterzaehlerStand;
|
private int unterzaehlerStand;
|
||||||
|
|
||||||
public Unterzaehler(String art, Verbraucher meinVerbraucher, int zaehlerStand) {
|
public Unterzaehler(String art, Verbraucher meinVerbraucher, int zaehlerStand) {
|
||||||
super(art, meinVerbraucher, zaehlerStand);
|
super(art, meinVerbraucher, zaehlerStand);
|
||||||
this.unterzaehlerStand = unterzaehlerStand;
|
this.unterzaehlerStand = unterzaehlerStand;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Unterzaehler clone() throws CloneNotSupportedException{
|
protected Unterzaehler clone() throws CloneNotSupportedException {
|
||||||
return (Unterzaehler) super.clone();
|
return (Unterzaehler) super.clone();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnterzaehlerstand() {
|
public int getUnterzaehlerstand() {
|
||||||
|
|
|
@ -3,36 +3,41 @@ package Uebung_15_04;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.LineNumberReader;
|
||||||
|
|
||||||
public class BufferedReader_Writer {
|
public class BufferedReader_Writer {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader("src/Uebung_15_04/Mondnacht.txt"));
|
BufferedReader reader = new BufferedReader(new FileReader("src/Uebung_15_04/Mondnacht.txt"));
|
||||||
int i = 0;
|
LineNumberReader lnr = new LineNumberReader(reader);
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int wortAnzahl = 0;
|
int wortAnzahl = 0;
|
||||||
|
|
||||||
String zeile = reader.readLine();
|
String zeile = lnr.readLine();
|
||||||
|
|
||||||
while (zeile != null) {
|
while (zeile != null) {
|
||||||
i++;
|
System.out.println("Zeile " + lnr.getLineNumber() + ": " + zeile);
|
||||||
System.out.println("Zeile " + i + ": " + zeile);
|
|
||||||
|
|
||||||
String[] w = zeile.split(" ");
|
String[] w = zeile.split(" ");
|
||||||
wortAnzahl += w.length;
|
wortAnzahl += w.length;
|
||||||
|
|
||||||
for (String wort : w) {
|
for (String wort : w) {
|
||||||
counter += wort.length();
|
char[] c = wort.toCharArray();
|
||||||
|
for (int i = 0; i <= c.length - 1; i++) {
|
||||||
|
if (Character.isLetter(c[i])) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
zeile = reader.readLine();
|
zeile = lnr.readLine();
|
||||||
|
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
System.out.println("Anzahl der Wörter: " + wortAnzahl);
|
System.out.println("Anzahl der Wörter: " + wortAnzahl);
|
||||||
System.out.println("Anzahl der Buchstaben: " + counter);
|
System.out.println("Anzahl der Buchstaben: " + counter);
|
||||||
System.out.println("Anzahl der Zeilen: " + i);
|
System.out.println("Anzahl der Zeilen: " + lnr.getLineNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
package Uebung_15_04;
|
package Uebung_15_04;
|
||||||
|
|
||||||
public class MainSerialisierung {
|
import java.io.*;
|
||||||
|
|
||||||
|
public class MainSerialisierung {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO Auto-generated method stub
|
// Erstelle ein Produkt
|
||||||
|
Product produkt1 = new Product("Handy" , "Schwarz" , 599.99);
|
||||||
|
|
||||||
|
// Dateiname für die Serialisierung
|
||||||
|
|
||||||
|
// Serialisierung
|
||||||
|
|
||||||
|
// Deserialisierung und Ausgabe
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// Methode zur Serialisierung eines Produkts
|
||||||
|
|
||||||
|
// Methode zur Deserialisierung eines Produkts
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package Uebung_Collections;
|
||||||
|
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Uebung1_Stack {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner (System.in);
|
||||||
|
String eingabe;
|
||||||
|
while(!(eingabe = sc.nextLine()).equals("q")) {
|
||||||
|
String ausdruck = "";
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0 ; i < eingabe.length(); i++) {
|
||||||
|
ausdruck += eingabe.charAt(i);
|
||||||
|
}
|
||||||
|
StreamTokenizer st = new StreamTokenizer(ausdruck);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Item {
|
||||||
|
|
||||||
|
// Konstruktor
|
||||||
|
Item(char z, int w) {
|
||||||
|
zeichen = z;
|
||||||
|
prio = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
char zeichen;
|
||||||
|
int prio;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package Uebung_Collections;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Uebung2_Set {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Pruefung p1 = new Pruefung(10);
|
||||||
|
|
||||||
|
Student student1 = new Student(12345, "Max Mustermann");
|
||||||
|
Student student2 = new Student(12346, "Beispiel Student");
|
||||||
|
Student student3 = new Student(12345, "Max Mustermann");
|
||||||
|
|
||||||
|
p1.anmelden(student1);
|
||||||
|
p1.anmelden(student2);
|
||||||
|
p1.anmelden(student3);
|
||||||
|
|
||||||
|
// Ausgabe der angemeldeten Studenten
|
||||||
|
for (Student s : p1.getAnmeldungen().values()) {
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Student {
|
||||||
|
private int matrikelNum;
|
||||||
|
private String studName;
|
||||||
|
|
||||||
|
public Student(int matrikelNum, String studName) {
|
||||||
|
this.matrikelNum = matrikelNum;
|
||||||
|
this.studName = studName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Student mit der Matrikelnummer " + matrikelNum + " und Name " + studName
|
||||||
|
+ " hat sich erfolgreich für die Prüfung angemeldet";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMatrikelNum() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return matrikelNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pruefung {
|
||||||
|
private int pruefungsNum;
|
||||||
|
private Map<Integer, Student> anmeldungen;
|
||||||
|
|
||||||
|
public Pruefung(int pruefungsNum) {
|
||||||
|
this.anmeldungen = new HashMap<>();
|
||||||
|
this.pruefungsNum = pruefungsNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void anmelden(Student student) {
|
||||||
|
anmeldungen.put(student.getMatrikelNum(), student);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, Student> getAnmeldungen() {
|
||||||
|
return anmeldungen;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package Uebung_Collections;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Uebung3_Queue implements Comparator <String>{
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Queue <String> statusQueue = new PriorityQueue<String>();
|
||||||
|
|
||||||
|
statusQueue.offer("Gold");
|
||||||
|
statusQueue.offer("Bronze");
|
||||||
|
statusQueue.offer("Silber");
|
||||||
|
|
||||||
|
Queue <String> ausgabe = sortiereNachPrio(statusQueue);
|
||||||
|
|
||||||
|
for (String string : ausgabe) {
|
||||||
|
System.out.println(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Queue<String> sortiereNachPrio(Queue <String> status){
|
||||||
|
|
||||||
|
Queue <String> queue = new PriorityQueue<String>(status);
|
||||||
|
|
||||||
|
|
||||||
|
Iterator <String> it = queue.iterator();
|
||||||
|
|
||||||
|
while(it.hasNext()) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(String o1, String o2) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package Uebung_Exceptions;
|
||||||
|
|
||||||
|
public class Aufgabe1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package Uebung_Generics;
|
||||||
|
|
||||||
|
public class Aufgabe2 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package Uebung_Generics;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Sortierung_Aufgabe {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int[] zahlen = new int[10];
|
||||||
|
|
||||||
|
for (int i = 0; i < zahlen.length; i++) {
|
||||||
|
int random = (int) (Math.random() * 100) + 1;
|
||||||
|
zahlen[i] = random;
|
||||||
|
}
|
||||||
|
// Arrays.sort(zahlen);
|
||||||
|
sortieren(zahlen);
|
||||||
|
System.out.println(Arrays.toString(zahlen));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Comparable<T>> void sortieren(T[] arr) {
|
||||||
|
|
||||||
|
for (int i = 0; i < arr.length; i++) {
|
||||||
|
int minIndex = i;
|
||||||
|
for (int j = i + 1; j < arr.length; j++) {
|
||||||
|
if (arr[j].compareTo(arr[minIndex]) < 0) {
|
||||||
|
minIndex = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
T temp = arr[minIndex];
|
||||||
|
arr[minIndex] = arr[i];
|
||||||
|
arr[i] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package Übungsstunde_Collections_27_05;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Aufgabe1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
List<Integer> list1 = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
list1.add(2);
|
||||||
|
list1.add(5);
|
||||||
|
list1.add(7);
|
||||||
|
list1.add(4);
|
||||||
|
list1.add(2);
|
||||||
|
|
||||||
|
List<Integer> liste2 = listeOhneDoppelteWerte(list1);
|
||||||
|
System.out.println(liste2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Integer> listeOhneDoppelteWerte(List<Integer> liste) {
|
||||||
|
|
||||||
|
// Set<Integer> neueListe = new HashSet<Integer>();
|
||||||
|
List<Integer> neueListe = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
for (Integer intWert : liste) {
|
||||||
|
|
||||||
|
if (!neueListe.contains(intWert)) {
|
||||||
|
neueListe.add(intWert);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// List<Integer> ausgabeListe = new ArrayList<>(neueListe);
|
||||||
|
|
||||||
|
return neueListe;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package Übungsstunde_Collections_27_05;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Aufgabe2 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Set<String> set1 = new HashSet<>();
|
||||||
|
set1.add("hallo");
|
||||||
|
// set1.add("wie");
|
||||||
|
set1.add("wie gehts?");
|
||||||
|
|
||||||
|
Set<String> set2 = new HashSet<>();
|
||||||
|
set2.add("gut");
|
||||||
|
// set2.add("und");
|
||||||
|
set2.add("dir?");
|
||||||
|
|
||||||
|
Set<String> vereinigtesSet = setsVereinigen(set1, set2);
|
||||||
|
|
||||||
|
System.out.println(vereinigtesSet);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> setsVereinigen(Set<String> set1, Set<String> set2) {
|
||||||
|
|
||||||
|
Set<String> neuerSet = new HashSet<>(set1);
|
||||||
|
|
||||||
|
neuerSet.addAll(set2);
|
||||||
|
|
||||||
|
return neuerSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package Übungsstunde_Collections_27_05;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
public class Aufgabe3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Queue<Integer> queueTest = new LinkedList<Integer>();
|
||||||
|
|
||||||
|
queueTest.offer(2);
|
||||||
|
queueTest.offer(6);
|
||||||
|
queueTest.offer(4);
|
||||||
|
queueTest.offer(3);
|
||||||
|
queueTest.offer(1);
|
||||||
|
|
||||||
|
int n = 2;
|
||||||
|
|
||||||
|
Queue<Integer> ausgabeQueue = entferneVonQueue(queueTest, n);
|
||||||
|
|
||||||
|
for (Integer ausgabe : ausgabeQueue) {
|
||||||
|
System.out.println(ausgabe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Queue<Integer> entferneVonQueue(Queue<Integer> queueIn, int n) {
|
||||||
|
|
||||||
|
Queue<Integer> queueOut = new LinkedList<Integer>(queueIn);
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
System.out.println("n darf nicht 0 sein!");
|
||||||
|
}
|
||||||
|
while (!queueOut.isEmpty() && i < n) {
|
||||||
|
i++;
|
||||||
|
queueOut.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return queueOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue