java - How will this code affect a linked list? -
i have code , want make sure understand how affect linked list. coded , printed first number of list in case 4. list [4,7,1,7,2,0], code make list become [4].
node x = head; while (x != null) { while ((x.next != null) && (x.next.item >= x.item)) { x.next = x.next.next; } x = x.next; }
i'm not sure i'm understanding why, , that's if code correct. given code presumably i'm supposed understand without coding it.
i suspect that:
x.next = x.next.next;
should
x = x.next;
Comments
Post a Comment