Java:
import java.util.*;
import java.text.*;
import java.io.*;
class Present{
String description;
int priorität;
Present(String description, int priority){
this.description = description; this.priority = priority;
}
Present(String description){
this.description = description;
}
Present(int priority){
this.priority = priority;
}
}
class Node{
Present wish;
Node next;
Node (Present wish) {this.wish = wish; }
}
public class WishList{
public static void addWish(Present wish){
Node p = new Node (wish);
if (head == null){
head = p;
}else{
tail.next = p;
}
tail = p;
}
public static void deleteWish(String description){
Node p = head;
Node prev = null;
while (p != null && p.description != description){
prev = p;
p = p.next;
}
if (p != null){
if (p == head){
head = p.next;
}else{
prev.next = p.next;
}
}
}
public static void printWish(){
Node p = head;
while (p != null){
System.out.println(p);
p = p.next;
}
}
public static void printWish(int priority){
Node p = new Node (priority);
while (p != null){
if (p.priority > priority) System.out.println(p.priority);
p = p.next;
}
}
public static void main(String[]Args){
System.out.println("1:Add wish 2:Delete wish" +
" 3:Show wish list 4:Show wishes with a certain priority");
int x = In.readInt();
if (x == 1){
System.out.println("Enter description");
String s = In.readInt();
System.out.println("Enter priority");
int n = In.readInt();
wish = Present (s, n);
addWish (wish);
}else{
if (x == 2){
System.out.println("Enter the description of the wish you want to delete");
String s = In.readInt();
deleteWish(s);
}else{
if (x == 3){
printWish();
}else{
if (x == 4){
System.out.println("Enter priority");
int n = In.readInt();
printWish(n);
}else{
System.out.println("Restart Program");
}
}
}
}
}
}
Guten Abend, ich sitz nun seit längerem an dieser Aufgabe und oben seht ihr wie weit ich bisher gekommen bin. Ich komm zurzeit nicht weiter, weil ich mit der einfach verketteten Liste Verständnisprobleme habe. Ich weiß aufgrund meines Buches wie ich Knoten verkette, lösche, einfüge usw., aber das alles nur mit einfachen Datentypen(int,String), ich weiß nicht wie ich das mit einem Objekt (class Present) mache und ich weiß auch nicht wie ich nur auf die int priority der Present Klasse in einer Liste zugreife und dann die gesamte Klasse ausgebe. Ich hoffe ihr könnt mir weiterhelfen und Tipps geben (ich antworte erst morgen früh).
LG
Woody
P.S.: Der Compiler gibt ganz viele Fehler aus, was mir klar ist und euch höchstwahrscheinlich noch eher. Wenn erwünscht ist, dass ich die Fehlermeldung trotzdem poste, kann ich das nachreichen...