#include<stdio.h>
#include<conio.h>
struct node
{
int info;
struct node *link;
};
struct node *first=NULL,*temp,*first1,*next,*rfirst;
int item;
void insert()
{
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;
first=nn;
}
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;
nn->link=NULL;
if(first==NULL)
{
first=nn;
return;
}
temp=first;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=nn;
}
void insordsll()
{
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=NULL;
first=nn;
return;
}
if(nn->info<=first->info)
{
nn->link=first;
first=nn;
return;
}
temp=first;
while((temp->link!=NULL)&&temp->link->info<=nn->info)
{
temp=temp->link;
}
nn->link=temp->link;
temp->link=nn;
}
void delitem()
{
struct node *dnode;
if(first==NULL)
{
printf("\n list is empty:");
return;
}
dnode=first;
first=first->link;
free(dnode);
}
void dellastsll()
{
struct node *prev;
if(first==NULL)
{
printf("\n list is empty:");
return;
}
if(first->link==NULL)
{
free(first);
return;
}
prev=NULL;
temp=first;
while(temp->link!=NULL)
{
prev=temp;
temp=temp->link;
}
prev->link=NULL;
free(temp);
}
void delspesll()
{
struct node *prev;
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
printf("\n enter item for delet:");
scanf("%d",&item);
if(first->info==item)
{
temp=first;
first=temp->link;
free(temp);
return;
}
prev=first;
temp=first->link;
while((temp->link!=NULL)&&temp->info!=item)
{
prev=temp;
temp=temp->link;
}
if(temp->info!=item)
{
printf("\n node not found:");
return;
}
prev->link=temp->link;
free(temp);
}
void display()
{
temp=first;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void display2()
{
temp=first1;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void display3()
{
temp=rfirst;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void splitsll()
{
if(first=='\0')
{
printf("\n list is empty:");
return;
}
printf("\n enter item for split:");
scanf("%d",&item);
temp=first;
while(temp->info!=item)
temp=temp->link;
first1=temp->link;
temp->link=NULL;
}
void mergesll()
{
if(first==NULL)
{
first=first1;
return;
}
if(first1==NULL)
{
return;
}
temp=first;
while(temp->link!=NULL)
temp=temp->link;
temp->link=first1;
}
void reverssll()
{
if(first==NULL)
{
rfirst=NULL;
return;
}
rfirst=NULL;
while(first!=NULL)
{
next=first->link;
first->link=rfirst;
rfirst=first;
first=next;
}
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 0)for exit:");
printf("\n 1)for insert:");
printf("\n 2)for display:");
printf("\n 3)for insert at last:");
printf("\n 4)for insert in order:");
printf("\n 5)for delet frist:");
printf("\n 6)for delet last:");
printf("\n 7)for delet specific item:");
printf("\n 8)for split list:");
printf("\n 9)for second list:");
printf("\n 10)for merge list:");
printf("\n 11)for revers list:");
printf("\n 12)for display revers:");
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insert();
break;
case 2:display();
break;
case 3:insend();
break;
case 4:insordsll();
break;
case 5:delitem();
break;
case 6:dellastsll();
break;
case 7:delspesll();
break;
case 8:splitsll();
break;
case 9:display2();
break;
case 10:mergesll();
break;
case 11:reverssll();
break;
case 12:display3();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}
#include<conio.h>
struct node
{
int info;
struct node *link;
};
struct node *first=NULL,*temp,*first1,*next,*rfirst;
int item;
void insert()
{
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;
first=nn;
}
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;
nn->link=NULL;
if(first==NULL)
{
first=nn;
return;
}
temp=first;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=nn;
}
void insordsll()
{
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=NULL;
first=nn;
return;
}
if(nn->info<=first->info)
{
nn->link=first;
first=nn;
return;
}
temp=first;
while((temp->link!=NULL)&&temp->link->info<=nn->info)
{
temp=temp->link;
}
nn->link=temp->link;
temp->link=nn;
}
void delitem()
{
struct node *dnode;
if(first==NULL)
{
printf("\n list is empty:");
return;
}
dnode=first;
first=first->link;
free(dnode);
}
void dellastsll()
{
struct node *prev;
if(first==NULL)
{
printf("\n list is empty:");
return;
}
if(first->link==NULL)
{
free(first);
return;
}
prev=NULL;
temp=first;
while(temp->link!=NULL)
{
prev=temp;
temp=temp->link;
}
prev->link=NULL;
free(temp);
}
void delspesll()
{
struct node *prev;
if(first==NULL)
{
printf("\n list is empty:");
getch();
return;
}
printf("\n enter item for delet:");
scanf("%d",&item);
if(first->info==item)
{
temp=first;
first=temp->link;
free(temp);
return;
}
prev=first;
temp=first->link;
while((temp->link!=NULL)&&temp->info!=item)
{
prev=temp;
temp=temp->link;
}
if(temp->info!=item)
{
printf("\n node not found:");
return;
}
prev->link=temp->link;
free(temp);
}
void display()
{
temp=first;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void display2()
{
temp=first1;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void display3()
{
temp=rfirst;
while(temp!=NULL)
{
printf("\n %d",temp->info);
temp=temp->link;
}
getch();
}
void splitsll()
{
if(first=='\0')
{
printf("\n list is empty:");
return;
}
printf("\n enter item for split:");
scanf("%d",&item);
temp=first;
while(temp->info!=item)
temp=temp->link;
first1=temp->link;
temp->link=NULL;
}
void mergesll()
{
if(first==NULL)
{
first=first1;
return;
}
if(first1==NULL)
{
return;
}
temp=first;
while(temp->link!=NULL)
temp=temp->link;
temp->link=first1;
}
void reverssll()
{
if(first==NULL)
{
rfirst=NULL;
return;
}
rfirst=NULL;
while(first!=NULL)
{
next=first->link;
first->link=rfirst;
rfirst=first;
first=next;
}
}
void main()
{
int ch;
do
{
clrscr();
printf("\n 0)for exit:");
printf("\n 1)for insert:");
printf("\n 2)for display:");
printf("\n 3)for insert at last:");
printf("\n 4)for insert in order:");
printf("\n 5)for delet frist:");
printf("\n 6)for delet last:");
printf("\n 7)for delet specific item:");
printf("\n 8)for split list:");
printf("\n 9)for second list:");
printf("\n 10)for merge list:");
printf("\n 11)for revers list:");
printf("\n 12)for display revers:");
printf("\n enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 0:break;
case 1:insert();
break;
case 2:display();
break;
case 3:insend();
break;
case 4:insordsll();
break;
case 5:delitem();
break;
case 6:dellastsll();
break;
case 7:delspesll();
break;
case 8:splitsll();
break;
case 9:display2();
break;
case 10:mergesll();
break;
case 11:reverssll();
break;
case 12:display3();
break;
default:printf("\n invalid input:");
getch();
}
}while(ch!=0);
}
No comments:
Post a Comment