FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
803 views
in Manipal University Jaipur B.Tech(CSE-III Sem) Data Structure Lab by Goeduhub's Expert (7.6k points)
Program to Insert a node at end of Circular Linked list

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Program to Insert a node at end of Circular Linked list

Algorithm

Step 1: IF PTR = NULL

 Write OVERFLOW
   Go to Step 1
  [END OF IF]

Step 2: SET NEW_NODE = PTR

Step 3: SET PTR = PTR -> NEXT

Step 4: SET NEW_NODE -> DATA = VAL

Step 5: SET NEW_NODE -> NEXT = HEAD

Step 6: SET TEMP = HEAD

Step 7: Repeat Step 8 while TEMP -> NEXT != HEAD

Step 8: SET TEMP = TEMP -> NEXT

[END OF LOOP]

Step 9: SET TEMP -> NEXT = NEW_NODE

Step 10: EXIT

Program

#include <stdio.h>

#include <stdlib.h>

#include<conio.h>

struct node   

{  

    int data;  

    struct node *next;   

};  

struct node *head; 

void lastinsert ();

void display(); 

void main ()  

    int choice,item;  

    do   

    {  

        lastinsert();  

        printf("\nPress  1 to insert more  and press 0 to display the list\n");  

        scanf("%d",&choice);  

    }while(choice == 1);

    if (choice==0);

    display();

}

void lastinsert()  

{  

    struct node *ptr,*temp;   

    int item;  

    ptr = (struct node *)malloc(sizeof(struct node));  

    if(ptr == NULL)  

    {  

        printf("\nOVERFLOW\n");  

    }  

    else  

    {  

        printf("\nEnter the data part to insert at last : ");  

        scanf("%d",&item);  

        ptr->data = item;  

        if(head == NULL)  

        {  

            head = ptr;  

            ptr -> next = head;    

        }  

        else  

        {  

            temp = head;  

            while(temp -> next != head)  

            {  

                temp = temp -> next;  

            }  

            temp -> next = ptr;   

            ptr -> next = head;  

        }  

        printf("\nnode inserted\n");  

    }  

void display()  

{  

    struct node *ptr;  

    ptr=head;  

    if(head == NULL)  

    {  

        printf("\nnothing to print");  

    }     

    else  

    {  

        printf("\n nodes are  \n");            

        while(ptr -> next != head)  

        {       

            printf("%d--->", ptr -> data);  

            ptr = ptr -> next;  

        }  

        printf("%d--->", ptr -> data);  

    }  

}  

Output

output


For more Manipal University Jaipur B.Tech CSE-III Sem Data Structure Lab Experiments Click here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...