开发者

Circular singly-linked list

This is a homework assignment

"Develop a structure for holding a singly-linked list. Create a list with a cycle. Create an algorithm that makes sure that the list is circular (the structure for holding elements of the list must be implemented by you)"

It probably sounds confusing and the fact that I am tr开发者_开发知识库anslating doesn't help. As I understand it, I need to create a custom singly linked list, which would go back to the first item after reaching its end.

I would really appreciate any ideas on how to do it.


Think about what each node in a singly linked list "knows" (i.e. what data it stores). Then think about what it means to make a circular list. What's the "next" element after the last one?

Hopefully that's enough of a hint to get you started.


You only need a pointer to the head node which you should be sure not to lose as you make additions to and deletions from your list.A circular list is traversed using the do...while construct as against the while construct you use for traversing a singly-linked list.Rest of the operations are pretty much the same as for a singly-linked list.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜