Please help? this is a problem to create link list and adding a number at front and end

this program works fine when i insert at beginning but when i insert at end it is not working please help???
#include<stdio.h>
#include<stdlib.h>
struct node
{int data;
struct node *link;}*new,*head,tail;
void create();
void dispaly();
void newstart();
void end();
int main()
{ int f;
create();
display();
printf("\n1 to add at bignning,2 to add at end and 3 to add at loc\n");
scanf("%d",&f);
if(f==1)
{
newstart();
}
if(f==2)
{
newend();
}
}
void create()
{ int c;
do
{
new=(struct node
)malloc(sizeof(struct node));
printf(“enter a value\n”);
scanf("%d",&new->data);
new->link=NULL;
if(head==NULL)
{head=new;
tail=new;}
else
{
tail->link=new;
tail=new;
}
printf(“enter 1 to continue\n”);
scanf("%d",&c);
}
while(c==1);
}
void display()
{ struct node *temp;
printf(“your link is\n”);
temp=head;
do
{printf("%d\t",temp->data);
temp=temp->link;
}
while(temp!=NULL);
}
void newstart()
{
struct node *bigning,temp1;
bigning=(struct node
)malloc(sizeof(struct node));
printf(“enter the value to add at bigning\n”);
scanf("%d",&bigning->data);
bigning->link=head;
temp1=bigning;
do
{
printf("%d\t",temp1->data);
temp1=temp1->link;
}
while(temp1!=NULL);
}
void newend()
{
struct node *end,*temp1,temp2;
end=(struct node
)malloc(sizeof(struct node));
printf(“enter a number\n”);
scanf("%d",end->data);
end->link=NULL;
temp1=head;
do
{
temp1=temp1->link;
}
while(temp1->link!=NULL);
temp1->link=end;
temp2=head;
do
{
printf("%d",temp2->data);
temp2=temp2->link;
}
while(temp2!=NULL);
}

Temp2 is not declared as a pointer…check if it works after correcting that

1 Like

Kindly upload code somewhere and share link.
It looks messy. :slight_smile:

1 Like