Write LinkedOps with your own singly linked list (a Node class with value and next, plus head and tail references — no java.util lists). Read integers until the end of input, appending each with addLast. Then:
- print the list (
1 -> 1 -> 2); - print the middle value with the slow/fast pointer technique (for an even length, the second of the two middle nodes);
- remove every node equal to its predecessor and print how many were removed;
- reverse the list in place in one pass and print it;
- append 0 (this checks that your
tailis still correct) and print.
For the input
1 1 2 3 3 3 4
the program prints
List: 1 -> 1 -> 2 -> 3 -> 3 -> 3 -> 4
Middle: 3
Removed 3 adjacent duplicate(s): 1 -> 2 -> 3 -> 4
Reversed: 4 -> 3 -> 2 -> 1
Add 0: 4 -> 3 -> 2 -> 1 -> 0