开发者

Array representation of linked lists

开发者 https://www.devze.com 2023-01-26 21:21 出处:网络
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 simpl开发者_运维技巧e implementation of linked lists using

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 simpl开发者_运维技巧e 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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消