I am reading Algorithms in C++ book by Robert Sedgwick. It was mentioned that linked lists can be represented by arrays. Can any one show the simple implementation of linked lists using arrays ?
Is it possible to implement Josephous problem using array implementation of linked lists ? If possible a sample implementation would be helpful.
Thanks!
Instead of a pointer or reference to the next element of the linked list, record the index in the array of the next element. Use an index that cannot possibly be an array index (e.g. -1) to indicate the end of the list.
Given you're asking then for a solution to a well-known and much solved problem, I'll assume it's an assignment and leave the solution to the reader :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With