Program for implementation and operation on linked list
Related Tags:-create | start | temp | delete | reverse | search | position
#include
#include
#include
struct node
{
int info;
struct node *link;
}*start;
void create(int data)
{
struct node *q,*temp;
temp=malloc(sizeof(struct node));
temp->info=data;
temp->link=NULL;
if(start==NULL)
start=temp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=temp;
}
}
void display()
{
struct node *temp;
temp=start;
if(start==NULL)
printf("\nList Is Empty");
else
{
while(temp!=NULL)
{
printf("%d\t",temp->info);
temp=temp->link;
}
}
}
void insbeg(int data)
{
struct node *temp;
temp=malloc(sizeof(struct node));
temp->info=data;
temp->link=start;
start=temp;
}
void insmid(int data,int pos)
{
int i;
struct node *q,*temp;
temp=malloc(sizeof(struct node));
temp->info=data;
q=start;
for(i=1;i
temp->link=q->link;
q->link=temp;
}
void insend(int data)
{
struct node *temp,*q;
q=start;
temp=malloc(sizeof(struct node));
temp->info=data;
while(q->link!=NULL)
q=q->link;
q->link=temp;
temp->link=NULL;
}
void delfir()
{
struct node *temp;
temp=start;
start=start->link;
free(temp);
}
void delmid(int data)
{
struct node *temp,*q;
q=start;
while(q->link->link!=NULL)
{
if(q->link->info==data)
{
temp=q->link;
q->link=temp->link;
free(temp);
}
q=q->link;
}
}
void delend()
{
struct node *q,*temp;
q=start;
while(q->link->link!=NULL)
q=q->link;
temp=q->link;
q->link=NULL;
free(temp);
}
void rev()
{
struct node *p1,*p2,*p3;
p1=start;
p2=p1->link;
p3=p2->link;
p1->link=NULL;
p2->link=p1;
while(p3!=NULL)
{
p1=p2;
p2=p3;
p3=p3->link;
p2->link=p1;
}
start=p2;
}
void delpos(int pos)
{
int i;
struct node *q,*temp;
q=start;
for(i=1;i
temp=q->link;
q->link=temp->link;
free(temp);
}
void search(int data)
{
int i=0,flag=1;
struct node *temp;
temp=start;
while(temp!=NULL)
{
i++;
if(temp->info==data)
{
printf("\n%d is found at %d position",data,i);
flag=0;
break;
}
temp=temp->link;
}
if(flag==1)
printf("%d is not found",data);
}
void searchpos(int pos,int n)
{
int i;
struct node *temp;
temp=start;
if(pos>n)
printf("\nyou enter wrong position");
else
{
for(i=1;i
printf("\n%d is found at %d position",temp->info,i);
}
}
void menu()
{
int ch,n,num,i,pos;
puts("\n\n1:for create list");
puts("2:for display");
puts("3:for exit");
puts("4:for insertion at begining");
puts("5:for insertion at between");
puts("6:for insertion at end");
puts("7:for delete first element");
puts("8:for deletion at between");
puts("9:for delete last element");
puts("10:for reverse the list");
puts("11:for delete element by position");
puts("12:for searching the element");
puts("13:for searching the element by position");
printf("\nenter your choice:- ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nhow many node you want to enter:- ");
scanf("%d",&n);
for(i=0;i
0 comments:
Post a Comment