#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct circle
{
int no;
struct circle *next;
};
typedef struct circle link;
void create();
void firstinsert();
void lastinsert();
void firstdelete();
void lastdelete();
void display();
link *start=NULL,*ptr=NULL;
void main()
{
int ch;
char choice;
clrscr();
do
{
printf("\n\n\t\t Circular linked list\n");
printf("1.Create\n");
printf("2.First Insert\n");
printf("3.Last Insert\n");
printf("4.First Delete\n");
printf("5.Last Delete\n");
printf("6.Display\n");
printf("7.Exit\n");
printf("Enter your choice-->>");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
break;
case 2:
firstinsert();
break;
case 3:
lastinsert();
break;
case 4:
firstdelete();
break;
case 5:
lastdelete();
break;
case 6:
display();
break;
case 7:
exit();
default:
printf("Sorry Wrong Choice...!!!\n");
}
printf("Do you want to continue-->>");
fflush(stdin);
scanf("%c",&choice);
}while(choice=='y' || choice=='Y');
}
void create()
{
if(start==NULL && ptr==NULL)
{
start=(link *)malloc(sizeof(link));
ptr=start;
}
else
{
ptr->next=(link *)malloc(sizeof(link));
ptr=ptr->next;
}
printf("Enter value-->>");
scanf("%d",&ptr->no);
ptr->next=start;
}
void firstinsert()
{
link *new1;
new1=(link *)malloc(sizeof(link));
printf("enter a value to insert-->>");
scanf("%d",&new1->no);
new1->next=start;
start=new1;
}
void lastinsert()
{
link *new1;
ptr=start;
while(ptr->next!=start)
{
ptr=ptr->next;
}
new1=(link *)malloc(sizeof(link));
printf("Enter a value to insert-->>");
scanf("%d",&new1->no);
new1->next=start;
ptr->next=new1;
}
void lastdelete()
{
link *ptr,*temp;
ptr=start;
while(ptr->next->next==start)
{
ptr=ptr->next;
ptr=temp;
temp=ptr->next;
ptr->next=start;
free(temp);
}
}
void firstdelete()
{
link *temp,*ptr1;
ptr1=start;
if(start->next==NULL)
{
free(start);
start=NULL;
}
else
{
temp=start;
start=ptr1->next;
free(temp);
}
}
void display()
{
link *ptr;
ptr=start;
printf("\n\nDisplay\n");
while(ptr->next!=start)
{
printf("%d\n",ptr->no);
ptr=ptr->next;
}
printf("%d\n",ptr->no);
}
for more codes you can Visit http://codesofprogramming.blogspot.in/
#include<conio.h>
#include<malloc.h>
struct circle
{
int no;
struct circle *next;
};
typedef struct circle link;
void create();
void firstinsert();
void lastinsert();
void firstdelete();
void lastdelete();
void display();
link *start=NULL,*ptr=NULL;
void main()
{
int ch;
char choice;
clrscr();
do
{
printf("\n\n\t\t Circular linked list\n");
printf("1.Create\n");
printf("2.First Insert\n");
printf("3.Last Insert\n");
printf("4.First Delete\n");
printf("5.Last Delete\n");
printf("6.Display\n");
printf("7.Exit\n");
printf("Enter your choice-->>");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
break;
case 2:
firstinsert();
break;
case 3:
lastinsert();
break;
case 4:
firstdelete();
break;
case 5:
lastdelete();
break;
case 6:
display();
break;
case 7:
exit();
default:
printf("Sorry Wrong Choice...!!!\n");
}
printf("Do you want to continue-->>");
fflush(stdin);
scanf("%c",&choice);
}while(choice=='y' || choice=='Y');
}
void create()
{
if(start==NULL && ptr==NULL)
{
start=(link *)malloc(sizeof(link));
ptr=start;
}
else
{
ptr->next=(link *)malloc(sizeof(link));
ptr=ptr->next;
}
printf("Enter value-->>");
scanf("%d",&ptr->no);
ptr->next=start;
}
void firstinsert()
{
link *new1;
new1=(link *)malloc(sizeof(link));
printf("enter a value to insert-->>");
scanf("%d",&new1->no);
new1->next=start;
start=new1;
}
void lastinsert()
{
link *new1;
ptr=start;
while(ptr->next!=start)
{
ptr=ptr->next;
}
new1=(link *)malloc(sizeof(link));
printf("Enter a value to insert-->>");
scanf("%d",&new1->no);
new1->next=start;
ptr->next=new1;
}
void lastdelete()
{
link *ptr,*temp;
ptr=start;
while(ptr->next->next==start)
{
ptr=ptr->next;
ptr=temp;
temp=ptr->next;
ptr->next=start;
free(temp);
}
}
void firstdelete()
{
link *temp,*ptr1;
ptr1=start;
if(start->next==NULL)
{
free(start);
start=NULL;
}
else
{
temp=start;
start=ptr1->next;
free(temp);
}
}
void display()
{
link *ptr;
ptr=start;
printf("\n\nDisplay\n");
while(ptr->next!=start)
{
printf("%d\n",ptr->no);
ptr=ptr->next;
}
printf("%d\n",ptr->no);
}
for more codes you can Visit http://codesofprogramming.blogspot.in/
No comments:
Post a Comment