Professional Documents
Culture Documents
h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h>
struct linklist{
int info;
struct linklist *next;
}*first ,*last;
struct linklist *ins_beg()
{
struct linklist *temp;
temp=(struct linklist *)malloc(sizeof(struct linklist));
temp->next=NULL;
// temp->info=x;
printf("enter a value:");
scanf("%d",&temp->info);
if(first==NULL)
{
first=temp;
last=temp;
last->next=first;
}
else
{
temp->next=first;
first=temp;
last->next=first;
}
return first;
}
// temp->info=x;
printf("enter a value:");
scanf("%d",&temp->info);
if(first==NULL)
{
first=temp;
last=temp;
last->next=first;
}
else
{
last->next=temp;
last=temp;
last->next=first;
}
return first;
}
void Display()
{
struct linklist *p;
if(first==NULL)
{
printf("There is no data");
}
else if(first==last)
{
printf("%d->",first->info);
}
else
{
p=first;
printf("\ndata is:");
while(p!=last)
{
printf("%d->",p->info);
p=p->next;
}
printf("%d ->",p->info);
}
// p=first;
// while(p!=NULL)
// {
// printf("%d -> ",p->info);
// p=p->next;
// }
// }
}
// printf("enter a value:");
// scanf("%d",&temp->info);
// if(first==NULL)
// {
// first=temp;
// }
// else
// {
// p=first;
// while(p->next!=NULL)
// { p=p->next;
// }
// p->next=temp;
// }
// return first;
// }
struct linklist *del_beg()
{
struct linklist *temp,*p;
temp=(struct linklist *)malloc(sizeof(struct linklist));
temp->next=NULL;
// printf("enter a value:");
// scanf("%d",&temp->info);
if(first==NULL)
{
printf("no node there");
}
else if(first==last)
{
printf("deleted element is %d",p->info);
free(first);
first=last=NULL;
}
else
{
p=first;
printf("deleted element is %d",p->info);
first=first->next;
last->next=first;
free(p);
p=NULL;
}
return first;
}
// printf("enter a value:");
// scanf("%d",&temp->info);
if(first==NULL)
{
printf("no node there");
}
else if(first==last)
{
printf("deleted element is %d",p->info);
free(first);
first=last=NULL;
}
else
{
p=first;
while(p !=last)
{ q=p;
p=p->next;
}
printf("deleted element is %d",p->info);
last=q;
last->next=first;
free(p);
p=NULL;
}
return first;
}
flag=1;
break;
}
else
{
p=p->next;
}
}
if(flag==1)
printf("value is%d",p->info);
else
printf("no match found");
// printf("enter a value:");
// scanf("%d",&temp->info);
// if(first==NULL)
// {
// first=temp;
// }
// else
// {
// p=first;
// while(p!=NULL && i<pos)
// { q=p;
// p=p->next;
// i++;
// }
// q->next=temp;
// temp->next=p;
// }
// return first;
// }
// if(pos==1)
// {
// first=del_beg(first);
// }
// else
// {
// p=first;
// while(p!=NULL && i<pos)
// { q=p;
// p=p->next;
// i++;
// }
// if(p!=NULL)
// { `
// q->next=p->next;
// free(p);
// p=NULL;
// }
// else
// {
// printf("there is no position avaible");
// }
// }
// return first;
// }
void main()
{
int choice=0,x;
struct linklist *temp,*first=NULL;
do{
first=ins_beg();
break;
case 2:
first=ins_end();
//first=ins_end(first);
break;
case 3:
del_beg();
//printf("enter position:");
//scanf("%d",&x);
//first=ins_pos(first,x);
break;
case 4:
del_end();
//first=del_beg(first);
break;
case 5:
//first=del_end(first);
break;
case 6:
//printf("enter position:");
//scanf("%d",&x);
//first=del_pos(first,x);
break;
case 7:
Display(first);
// break;
// case 11:
// break;
default:
printf("Invalid choice !!");
}
}while(choice!=8);
}