Showing posts with label linked list faqs. Show all posts
Showing posts with label linked list faqs. Show all posts

C program to compare two linked lists?

int compare_linked_lists(struct node *q, struct node *r) {
    static int flag;
   
    if((q==NULL ) && (r==NULL))
    {
         flag=1;
    }
    else
    {
        if(q==NULL || r==NULL)
        {
            flag=0;
        }
        if(q->data!=r->data)
        {
            flag=0;
        }
        else
        {
           compare_linked_lists(q->link,r->link);
        }
    }
    return(flag); }

C program to delete a tree?

Solutions:
 
clear(struct node* pNode)
{
if (pNode != NULL)
{
clear(pNode->left);
clear(pNode->right);
delete pNode;
}
}

Datastructure Linked list interview questions

Data Structure or Linkedlist interview questions
1)How do you reverse a singly linked list? How do you reverse a doubly linked list? Write a C program to do the same.
2)Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
3)How do you sort a linked list? Write a C program to sort a linked list.
4)How to declare a structure of a linked list?
5)Write a C program to implement a Generic Linked List.
6)How do you reverse a linked list without using any C pointers?
7)How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list.
8)How do you find the middle of a linked list? Write a C program to return the middle of a linked list.
9)If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
10)How to compare two linked lists? Write a C program to compare two linked lists.
11)How to create a copy of a linked list? Write a C program to create a copy of a linked list.
12)Write a C program to free the nodes of a linked list.
13)Can we do a Binary search on a linked list?
14)Write a C program to return the nth node from the end of a linked list.
15)How would you find out if one of the pointers in a linked list is corrupted or not?
16)Write a C program to insert nodes into a linked list in a sorted fashion.
17)Write a C program to remove duplicates from a sorted linked list.
18)How to read a singly linked list backwards?
19)How can I search for data in a linked list?

How to check whether a linked list is circular?

 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 point

Below 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:
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++