#include<stdio.h>
#include<conio.h>
struct node
{
int info;
struct node *link;
};
struct node *first=NULL,*temp2,*temp,*prev;
int item;
void insend()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(first==NULL)
{
nn->link=nn;
first=nn;
return;
}
temp=first;
while(temp->link!=first)
{
temp=temp->link;
}
temp->link=nn;
nn->link=first;
}
void insfircll()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
nn->link=first;
temp=first;
while(temp->link!=first)
temp=temp->link;
temp->link=nn;
first=nn;
}
void insordcll()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(first==NULL)
{
first=nn;
first->link=first;
return;
}
temp=first;
if(nn->info<=first->info)
{
while(temp->link!=first)
temp=temp->link;
nn->link=temp->link;
temp->link=nn;
first=nn;
return;
}
while((temp->link!=first)&&temp->link->info<=nn->info)
{
temp=temp->link;
}
nn->link=temp->link;
temp->link=nn;
}
void delfircll()
{
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
if(first==first->link)
{
free(first);
first=NULL;
}
temp=first;
temp2=first;
while(temp->link!=first)
temp=temp->link;
temp->link=first->link;
first=first->link;
free(temp2);
}
void dellascll()
{
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
if(first==first->link)
{
free(first);
first=NULL;
}
temp=first;
prev=NULL;
while(temp->link!=first)
{
prev=temp;
temp=temp->link;
}
prev->link=first;
free(temp);
}
void delitecll()
{
void displaycll()
{
temp=first;
while(temp->link!=first)
{
printf("\n %d",temp->info);
temp=temp->link;
}
printf("\n %d",temp->info);
getch();
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 0)for exit:");
printf("\n 1)for insert:");
printf("\n 2)for display:");
printf("\n 3)insert first:");
printf("\n 4)insert in order:");
printf("\n 5)delete first:");
printf("\n 6)delete last:");
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insend();
break;
case 2:displaycll();
break;
case 3:insfircll();
break;
case 4:insordcll();
break;
case 5:delfircll();
break;
case 6:dellascll();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}
#include<conio.h>
struct node
{
int info;
struct node *link;
};
struct node *first=NULL,*temp2,*temp,*prev;
int item;
void insend()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(first==NULL)
{
nn->link=nn;
first=nn;
return;
}
temp=first;
while(temp->link!=first)
{
temp=temp->link;
}
temp->link=nn;
nn->link=first;
}
void insfircll()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
nn->link=first;
temp=first;
while(temp->link!=first)
temp=temp->link;
temp->link=nn;
first=nn;
}
void insordcll()
{
struct node *nn;
nn=((struct node*)malloc(sizeof(nn)));
if(nn==NULL)
{
printf("\n memory not allocate:");
getch();
return;
}
printf("\n enter item:");
scanf("%d",&item);
nn->info=item;
if(first==NULL)
{
first=nn;
first->link=first;
return;
}
temp=first;
if(nn->info<=first->info)
{
while(temp->link!=first)
temp=temp->link;
nn->link=temp->link;
temp->link=nn;
first=nn;
return;
}
while((temp->link!=first)&&temp->link->info<=nn->info)
{
temp=temp->link;
}
nn->link=temp->link;
temp->link=nn;
}
void delfircll()
{
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
if(first==first->link)
{
free(first);
first=NULL;
}
temp=first;
temp2=first;
while(temp->link!=first)
temp=temp->link;
temp->link=first->link;
first=first->link;
free(temp2);
}
void dellascll()
{
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
if(first==first->link)
{
free(first);
first=NULL;
}
temp=first;
prev=NULL;
while(temp->link!=first)
{
prev=temp;
temp=temp->link;
}
prev->link=first;
free(temp);
}
void delitecll()
{
void displaycll()
{
temp=first;
while(temp->link!=first)
{
printf("\n %d",temp->info);
temp=temp->link;
}
printf("\n %d",temp->info);
getch();
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 0)for exit:");
printf("\n 1)for insert:");
printf("\n 2)for display:");
printf("\n 3)insert first:");
printf("\n 4)insert in order:");
printf("\n 5)delete first:");
printf("\n 6)delete last:");
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insend();
break;
case 2:displaycll();
break;
case 3:insfircll();
break;
case 4:insordcll();
break;
case 5:delfircll();
break;
case 6:dellascll();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}
No comments:
Post a Comment