# Program to Insert a node at end of Circular Linked list

0 like 0 dislike
803 views
Program to Insert a node at end of Circular Linked list

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

## 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;

};

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;

{

}

else

{

{

temp = temp -> next;

}

temp -> next = ptr;

}

printf("\nnode inserted\n");

}

void display()

{

struct node *ptr;

{

printf("\nnothing to print");

}

else

{

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

{

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

ptr = ptr -> next;

}

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

}

}

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.