Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi

Ich bin gerade dabei einen 2_3_4Baum zu implementieren und hatte eigentlich gehofft, dass ich meinen alten BBaum nur leicht verändern muss, aber ich habe Probleme bei den Konstruktoren ... am besten ich zeig es euch einfach:



class Node2_3_4<T extends Comparable<T>> {


//Atribute

public T[] keys;


public Node2_3_4<T>[] children;


// Konstruktoren

public Node2_3_4() {

for(int i=0; i<3; i++){

this.keys[i]=null;

}


for(int i=0; i<4; i++){

this.children[i]=null;

}


} ... 

An sich werden mir keine Fehler angezeigt aber wenn ich die datei, was heißt TestTree ausführe, kommt ne NullPointerException hat jemand eine Idee wie ich es verändern kann ohne jedes Objekt einzeln als Attribut zu wählen?

Node2_3_4.txt

Tree2_3_4.txt

TestTree2_3_4.txt

Hallo,


public Node2_3_4<T>[] children;

besagt, dass Du ein Array [] vom Typ T mit dem Namen children anlegst.

public Node2_3_4() {

    for(int i=0; i<3; i++)

	 this.keys[i]=null;

}

Hier greifst Du immer auf das 1-te Element zu. Frage Dich mal: Wie viele Elemente hat denn Dein Array?

HTH Phil

oder um es deutlicher zu formulieren: Du musst Deine Arrays noch initialisieren, z.B. im Konstruktor:

keys = new T[4];

Peter

Mir ist dabei sehr wohl bewusst, dass ich das Array noch nicht initialisiere, aber wenn ich nach dem üblichen Schema gehen würde, was heißt:


int size=3;

T[] objekt = T[size];

dann krieg ich ne Fehlermeldung, dass kein generisches Array dieser Art angelegt werden kann

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.