Reputation: 157
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 translating 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.
Upvotes: 1
Views: 1249
Reputation: 17
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.
Upvotes: 0
Reputation: 1500765
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.
Upvotes: 3