Massive view of linked lists

I read Algorithms in Robert Sedgwick's C ++ book. It was mentioned that linked lists can be represented by arrays. Can someone show a simple implementation of linked lists with arrays?

Is it possible to implement the Josephus problem using an implementation of an array of linked lists? If possible, an example implementation will be useful.

Thank!

+3
source share
1 answer

Instead of a pointer or a link to the next element of the linked list, write the index into an array of the next element. Use an index that cannot be an array index (e.g. -1) to indicate the end of the list.

, , :)

+11

Source: https://habr.com/ru/post/1777065/


All Articles