#include<stdio.h>
#include<conio.h>
typedef struct node
{
int num;
struct node *next;
}nod;
nod *head;
void begin(int item);
void end(int item);
void posi(int item,int loc);
void display(nod *head);
void emptylist(nod *head);
void main()
{
int choice,item,after,loc;
char ch;
clrscr();
//emptylist(head);
do
{
printf("\n\n1.insert at begin\n");
printf("2.insert at end\n");
printf("3.insert at position\n");
printf("4.display yhe list\n");
printf("enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter the data");
scanf("%d",&item);
begin(item);
break;
case 2:printf("enter the item\n");
scanf("%d",&item);
end(item);
break;
case 3:printf("enter the item");
scanf("%d",&item);
scanf("%d",&loc);
posi(item,loc);
break;
case 4:printf("\n display the list");
display(head);
break;
}
}while(choice!=5);
getch();
}
//void emptylist(node *head)
//{
// head='\0';
//
//}
void display(nod *head)
{
nod *p;
p=head;
while(p!='\0')
{
printf("%d\n",p->num);
p=p->next;
}
}
void begin(int item)
{
nod *p;
p=(nod *)malloc(sizeof(nod));
p->num=item;
if(head=='\0')
{
p->next='\0';
}
else
{
p->next=head;
}
head=p;
}
void end(int item)
{
nod *p,*loc;
p=(nod *)malloc(sizeof(nod));
p->num=item;
p->next='\0';
if(head=='\0')
{
head=p;
}
else
{
loc=head;
while(loc->next!='\0')
{
loc=loc->next;
}
loc->next=p;
}
}
void posi(int item,int loc)
{
nod *p,*tmp;
int k;
for(k=0,tmp=head;k<loc;k++)
{
tmp=tmp->next;
if(tmp=='\0')
{
printf("node in the list at less than one\n");
return;
}
}
tmp=(nod *)malloc(sizeof(nod));
tmp->num=item;
tmp->next=head->next;
head->next=tmp;
}
#include<conio.h>
typedef struct node
{
int num;
struct node *next;
}nod;
nod *head;
void begin(int item);
void end(int item);
void posi(int item,int loc);
void display(nod *head);
void emptylist(nod *head);
void main()
{
int choice,item,after,loc;
char ch;
clrscr();
//emptylist(head);
do
{
printf("\n\n1.insert at begin\n");
printf("2.insert at end\n");
printf("3.insert at position\n");
printf("4.display yhe list\n");
printf("enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter the data");
scanf("%d",&item);
begin(item);
break;
case 2:printf("enter the item\n");
scanf("%d",&item);
end(item);
break;
case 3:printf("enter the item");
scanf("%d",&item);
scanf("%d",&loc);
posi(item,loc);
break;
case 4:printf("\n display the list");
display(head);
break;
}
}while(choice!=5);
getch();
}
//void emptylist(node *head)
//{
// head='\0';
//
//}
void display(nod *head)
{
nod *p;
p=head;
while(p!='\0')
{
printf("%d\n",p->num);
p=p->next;
}
}
void begin(int item)
{
nod *p;
p=(nod *)malloc(sizeof(nod));
p->num=item;
if(head=='\0')
{
p->next='\0';
}
else
{
p->next=head;
}
head=p;
}
void end(int item)
{
nod *p,*loc;
p=(nod *)malloc(sizeof(nod));
p->num=item;
p->next='\0';
if(head=='\0')
{
head=p;
}
else
{
loc=head;
while(loc->next!='\0')
{
loc=loc->next;
}
loc->next=p;
}
}
void posi(int item,int loc)
{
nod *p,*tmp;
int k;
for(k=0,tmp=head;k<loc;k++)
{
tmp=tmp->next;
if(tmp=='\0')
{
printf("node in the list at less than one\n");
return;
}
}
tmp=(nod *)malloc(sizeof(nod));
tmp->num=item;
tmp->next=head->next;
head->next=tmp;
}