Circular linked list

In Single LL we will make the next points to NULL in Constructors , but in circular it not like that . how will it recognize that we are going to reaches to end now simply make the last->next points to null , ?

when we are creating the constructors we have taken the data only so it will create the both two things one data and next in node

Hey @Vikaspal,

As we are taking about a circular linked list.
So, there will be a loop.
Which means the next of the last node will point to the first node i.e. head of the linked list.
Correct?
image

To identify the end of the linked list we will simply check:
if(curr_node->next==head):
So, curr_node is the last node.

Hope, this would help.
give a like if you are satisfied.

@S18ML0016 i got ur point. The things is that while we are defining the constructor when we do
node (int data) {
data = data
next = null

}

so when we create the object it will create a node with data and null .
but node (int data) {
data = data
}

so here when create the object the we data and next is not have any values it may pointed to garbage.
so the my question is that it will not going to effect when we are creating the objects bcoz in the video itself next is not having any values?

Hello @Vikaspal

As per what i have understood.

It’s a good pratice to initialize a pointer to NULL because dereferencing a garbage pointer (or the dangling pointer) would lead to undefined results.

Thus, to prevent that we should initialize it to NULL.

@S18ML0016 got it thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.