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.

Überprüfen ob eine Liste vollständig und zusammenhängend in einer anderen Liste...

Empfohlene Antworten

Veröffentlicht

vorhanden ist:

Bin momentan bis hier:


	public static boolean subList(ListT list, ListT sublist) {

		IteratorT p1 = list.getIterator();

		IteratorT p2 = sublist.getIterator();

		p2.first();

		while (p1.hasMore() && p2.hasMore()) {

			if (list.retrieve(p1).equals(sublist.retrieve(p2))) {

				p1.next();

				p2.next();

			} else {

				return false;

			}// end if

		}// end while

		return true;

	}// end subList

Jaraz: code tags repariert

Was ist flasch an meiner Überlegung?

Vielen dank.

Ehrlich gesagt war es nicht so einfach, deinen Code zu lesen, als Anregung: Ich würde nicht jede Zeile in Code-Tags setzen.

So, wie ich es jetzt verstanden habe, überprüfst du, ob list und sublist genau gleich sind, aber nicht, ob sublist nur beinhaltet wird.

Ich würde das ungefähr so machen (bin kein Java-Programmierer):


p1.first();

p2.first();


while (p1.hasMore())

  if (list.retreive(p1).equals(sublist.retreive(p2)))

  {

    while (list.retreive(p1).equals(sublist.retreive(p2)) && p1.hasMore() && p2.hasMore() )

    {

      p1.next();

      p2.next();

      if (!p1.hasMore() ) return true;

    }

    p2.first();

  }

  else

    p1.next();


return false;

Ungetestet!!

Hallo...

erstmal vielen Dank für dein Antwort...vielleicht sollte ich das ganze noch weiter ausführen:

Ich geben in die Liste list 6 Elemente (Integer-Werte ein) und in die Liste sublist nur 4. jetzt soll geschaute werden ob die sublist in der list vollständig und zusammenhängend vorkommt.

Bsp.:

list <1,2,3,4,5,6>

sublist <3,4,5,6>

da muss jetzt true rauskommen.

Einen Fehler hab ich bei mir gefunden:

Es soll heißen:


      if (!p2.hasMore() ) return true;

Und Testen kann ichs net, hab leider kein Java hier in der Firma.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.