Singly
Singly
h>
#include<stdlib.h>
void insertleft(node**,node**);
void insertright(node**,node**);
void insertkey(node**,node**);
void insertpos(node**,node**);
void deletekey(node**,node**);
void deletepos(node**,node**);
void display(node*);
void reversedisplay(node*);
void odd_info(node*);
void even_info(node*);
void odd_pos(node*);
void even_pos(node*);
void max_element(node *);
int main()
{
int ch;
node *head=NULL,*tail=NULL;
do
{
printf("enter::\n1 to insert in right\n2 to insert in left\n3 to
insert by position\n4 to insert after a key\n5 to delete by key\n6 to
delete by position\n7 to display\n8 to reverse display\n9 to odd info
print\n10 to even position elements print\n11 to even info print\n12 to
odd position elements print\n13 to max_element\n:::");
scanf("%d",&ch);
switch(ch)
{
case 1:
insertright(&head,&tail);
break;
case 2:
insertleft(&head,&tail);
break;
case 3:
insertpos(&head,&tail);
break;
case 4:
insertkey(&head,&tail);
break;
case 5:
deletekey(&head,&tail);
break;
case 6:
deletepos(&head,&tail);
break;
case 7:
display(head);
break;
case 8:
reversedisplay(head);
break;
case 9:
odd_info(head);
break;
case 10:
even_pos(head);
break;
case 11:
even_info(head);
break;
case 12:
odd_pos(head);
break;
case 13:
max_element(head);
break;
default:
printf("wrong choice\n");
}
printf("enter 1 to continue:");
scanf("%d",&ch);
}while(ch==1);
return 0;
}
}
}
}
}
else if(tc==*tail)
{
*tail=tp;
tp->next=NULL;
free(tc);
}
else
{
tp->next=tc->next;
free(tc);
}
}
}
}
else if(pos==c)
{
tc=(*head)->next;
tp=tc;
while(tc->next!=NULL)
{
tp=tc;
tc=tc->next;
}
*tail=tp;
(*tail)->next=NULL;
free(tc);
}
else if(pos>1&&pos<c){
int h=1;
tc=(*head)->next;
tp=tc;
while(tc!=NULL)
{
h++;
if(pos==h)
{
break;
}
tp=tc;
tc=tc->next;
}
tp->next=tc->next;
free(tc);
}
}
}