I'm confused as to what this problem is asking for as an output. Can anyone clarify? You do not need to solve the problem. I just need help understanding what it is asking for!
What you're seeing there is a linked list where:
1
is the starting index;next
pointer.It may be better to think of it as:
start = 1
index: 0 1 2 3 4 5 6 7
char: H A C E B D F G
next: 0 4 5 6 2 3 7 0
and realise that:
1
gives you the character A
and a link of 4
.4
gives you the character B
and a link of 2
.2
gives you the character C
and a link of 5
.5
gives you the character D
and a link of 3
.Rearranging them sorted on list (following start/next
) order gives you:
start = 1
index: 1 4 2 5 3 6 7 0
char: A B C D E F G H
next: 4 2 5 3 6 7 0 0
So it's effectively the linked list:
A -> B -> C -> D -> E -> F -> G -> H -> H -> H ...
The expected result should just be the linked list in order (ABCDEFGH
) copied to a new array but, interestingly enough, H
points to itself rather than some special NULL value, so you will have to detect that as a special case.