How can we determine that a given list is linked list or not. only the pointer to the 1st node is given. you can't use any temp variable. the list is purely circular i.e. last node points to the first node?
Ans>
Problem : To find if the list is a circular linked list or not using just 1 pointer
1. Have a pointer head to the first element
2. Check And branch as follows
if (head -> next == head) Go to step 5
else if (head -> next == null) Go to step 6
else Go to Step 3
3. Delete the next node from the list as follows
head -> next = head -> next -> next;
4. Go to step 2
5. Print List is a circular list & exit
6. Print List is a Linked List and exit
No comments:
Post a Comment