How to check whether a linked list is circular?
Create two pointers, and set both to the start of the list. Update them as increment first pointer by one and second pointer by two if its a circular link list they will defenitely meet at some pointBelow is a sample program to check circular link list:-
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}}
Keywords:pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}}
circular linked list
circular linked list java
check if linked list is palindrome
circular linked list with one node
floyd's cycle-finding algorithm c++
circular linked list in c
reverse a linked list
circular linked list in c++
No comments:
Post a Comment