InterviewSolution
Saved Bookmarks
| 1. |
Can you tell me how to check whether a linked list is circular? |
|
Answer» Single Linked List Single Linked ListCIRCULAR Linked List Circular linked list is a variation of a linked list where the last node is pointing to the first node's information part. Therefore the last node does not point to null. Algorithm to find whether the given linked list is circularA very simple way to determine whether the linked list is circular or not
Let's look at the snippet where we code this algorithm. Create a structure for a linked listDeclare-Variable to store data of the node.-Pointer variable of struct type to store the address of next node.function of datatype tool isCircular(firstgode){-Store the value of first node in temp variable and make it traverse all nodes.-temp-firstgode-tempenext node pointed by temp(temp->next)-run until temp is at null or firstNodeif (temp at null) not circular and returns false if (temp points first node) return true as its circular. } function of datatype node newNode(data){-To insert NEW nodes and link each one of them to the previous node by storing the address of the new node to the previous one.-Then make them point to NULL.}In int main function-First insert nodes for circular linked list and check its nature by calling isCircular function.-Since it is true through if statement it prints "yes..-Second insert a normal linked list and check its nature by calling isCircular function. As its not circular it prints "no",",can-you-tell-me-how-to-check-whether-a-linked-list-is-circular,linked list 7539,55201,C INTERVIEW QUESTIONS|C INTERVIEW QUESTIONS FOR EXPERIENCED IN C INTERVIEW QUESTIONS,C Interview Questions,C Interview Questions For Experienced in C Interview Questions,What is the use of a semicolon (;) at the end of every program statement?,"It is majorly related to how the compiler reads( or parses) the entire code and breaks it into a set of instructions(or statements), to which semicolon in C acts as a boundary between TWO sets of instructions. |
|