forked from denyskon/info-java
BinaererSuchbaum/BinaererSuchbaumDemoSchueler.java aktualisiert
This commit is contained in:
parent
479aa8f06c
commit
48f0bd28bf
@ -1,61 +1,61 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BinaererSuchbaumDemoSchueler {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
BinaererSuchbaum<Double> baum = new BinaererSuchbaum<>();
|
||||
boolean laeuft = true;
|
||||
|
||||
while (laeuft) {
|
||||
System.out.println("\nBinärer Suchbaum - Menü:");
|
||||
System.out.println("0. Elemente automatisch hinzufügen");
|
||||
System.out.println("1. Element hinzufügen");
|
||||
System.out.println("2. Element suchen");
|
||||
System.out.println("3. Element löschen");
|
||||
System.out.println("4. Baum anzeigen (Inorder-Traversierung)");
|
||||
System.out.println("5. Programm beenden");
|
||||
System.out.print("Wähle eine Option: ");
|
||||
|
||||
int auswahl = scanner.nextInt();
|
||||
double element;
|
||||
switch (auswahl) {
|
||||
case 0:
|
||||
for (double i = -15; i <= 15; i+=0.5) {
|
||||
System.out.println("Zu hinzufügendes Element: " + i);
|
||||
baum.hinzufuegen(i);
|
||||
System.out.println("Element hinzugefügt.");
|
||||
}
|
||||
break;
|
||||
case 1 :
|
||||
System.out.print("Zu hinzufügendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
baum.hinzufuegen(element);
|
||||
System.out.println("Element hinzugefügt.");
|
||||
break;
|
||||
case 2 :
|
||||
System.out.print("Zu suchendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
boolean gefunden = baum.suchen(element) != null;
|
||||
System.out.println(gefunden ? "Element gefunden." : "Element nicht gefunden.");
|
||||
break;
|
||||
case 3 :
|
||||
System.out.print("Zu löschendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
baum.loeschen(element);
|
||||
System.out.println("Element gelöscht (falls vorhanden).");
|
||||
break;
|
||||
case 4 :
|
||||
System.out.println("Baum (Inorder-Traversierung):");
|
||||
baum.inorderAusgabe();
|
||||
break;
|
||||
case 5 :
|
||||
laeuft = false;
|
||||
System.out.println("Programm wird beendet.");
|
||||
break;
|
||||
default : System.out.println("Ungültige Auswahl. Bitte versuche es erneut."); break;
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
import java.util.Scanner;
|
||||
|
||||
public class BinaererSuchbaumDemoSchueler {
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
BinaererSuchbaum<Double> baum = new BinaererSuchbaum<>();
|
||||
boolean laeuft = true;
|
||||
|
||||
while (laeuft) {
|
||||
System.out.println("\nBinärer Suchbaum - Menü:");
|
||||
System.out.println("0. Elemente automatisch hinzufügen");
|
||||
System.out.println("1. Element hinzufügen");
|
||||
System.out.println("2. Element suchen");
|
||||
System.out.println("3. Element löschen");
|
||||
System.out.println("4. Baum anzeigen (Inorder-Traversierung)");
|
||||
System.out.println("5. Programm beenden");
|
||||
System.out.print("Wähle eine Option: ");
|
||||
|
||||
int auswahl = scanner.nextInt();
|
||||
double element;
|
||||
switch (auswahl) {
|
||||
case 0:
|
||||
for (double i = -15; i <= 15; i+=0.5) {
|
||||
System.out.println("Zu hinzufügendes Element: " + i);
|
||||
baum.hinzufuegen(i);
|
||||
System.out.println("Element hinzugefügt.");
|
||||
}
|
||||
break;
|
||||
case 1 :
|
||||
System.out.print("Zu hinzufügendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
baum.hinzufuegen(element);
|
||||
System.out.println("Element hinzugefügt.");
|
||||
break;
|
||||
case 2 :
|
||||
System.out.print("Zu suchendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
boolean gefunden = baum.suchen(element) != null;
|
||||
System.out.println(gefunden ? "Element gefunden." : "Element nicht gefunden.");
|
||||
break;
|
||||
case 3 :
|
||||
System.out.print("Zu löschendes Element: ");
|
||||
element = scanner.nextDouble();
|
||||
baum.loeschen(element);
|
||||
System.out.println("Element gelöscht (falls vorhanden).");
|
||||
break;
|
||||
case 4 :
|
||||
System.out.println("Baum (Inorder-Traversierung):");
|
||||
baum.inorderAusgabe();
|
||||
break;
|
||||
case 5 :
|
||||
laeuft = false;
|
||||
System.out.println("Programm wird beendet.");
|
||||
break;
|
||||
default : System.out.println("Ungültige Auswahl. Bitte versuche es erneut."); break;
|
||||
}
|
||||
}
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user