Witam,
Zmagam się z takim zadaniem, niestety nie można używać tutaj kolekcji.
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;
}
}
}
}