#include<stdio.h> #include<stdlib.h> struct node { int data; struct node * next; }; struct node *head=NULL; void insEnd(); void display(); void main() { int choice; do { printf("\n__MENU__\n1.Insert at the End\n2...EXIT...\n"); printf("\nENTER your choice\n"); scanf("%d",&choice); switch(choice) { case 1 :insEnd();break; case 2:printf("~~~~~~~THANK YOU~~~~~~~\n");break; default:printf("INVALID input !!!");break; } }while(choice!=2); } void insEnd() { struct node* temp,*newnode; temp=head; newnode=(struct node*)malloc(sizeof(struct node*)); printf("\nEnter element\n"); scanf("%d",&newnode->data); if(head==NULL) { head=newnode; newnode->next=head; } else { while(temp->next!=head) temp=temp->next; temp->next=newnode; newnode->next=head; } display(); } void display() { struct node* temp; temp=head; if(head==NULL) printf("List is empty !!!"); else { printf("List elements are :\t"); while(temp->next!=head) { printf("%d\t",temp->data); temp=temp->next; } printf("%d\n",temp->data); } }
|
|
Labels: Circular Single Linked List