Lista bez użycia kolekcji

0

Witam,

Zmagam się z takim zadaniem, niestety nie można używać tutaj kolekcji.

user image

Zrobiłem coś takiego, ale proszę o pomoc w rozwiązaniu:

public class Element {
	
	int val;
	Element next;
	Element prev;

}
public class Anchor {

	Element first;

	void removeAndRevert(int x) {

		Element ostatniDodatni, aktualny, staryFirst, pierwszyUjemny;
		Element nastepny;
		Element poprzedni;

		staryFirst = this.first;
		aktualny = this.first;
		poprzedni = this.first;

		if (aktualny.next != null) {
			if (aktualny.val < 0)
				this.first = null;
			if (aktualny.val >= 0) {
				aktualny = this.first;
				nastepny = aktualny.next;

				if (poprzedni.prev == null) {
					poprzedni.val = staryFirst.val;

				}
			}

		}

		if (aktualny.next == null) {
			if (aktualny.val < 0) {
				this.first = null;
				aktualny = this.first;

			}

			if (aktualny.val >= 0) {
				aktualny = staryFirst;

			}

		}

	}
}
1

bardzo skomplikowana captcha

0

Potrzebujesz jeszcze klasę List, która będzie zawierać wskaźnik na ostatni element listy tzn:

class List{
    private Element head;

   //...

}

Wtedy metody do operowania kolejnością i zawartością listy umieszczasz w tej klasie.

0

@Koziołek

Byłbym bardzo wdzięczny gdybyś przedstawił swój kod na rozwiązanie problemu :)

0

W takim razie czy wgl. jest coś poprawnego w moim kodzie przedstawionym w pierwszym poście?

1 użytkowników online, w tym zalogowanych: 0, gości: 1