I am making a single linked list program with various input and delete functions but for some reason none of the printf or scanf functions in user defined functions work. The code is executed but no input or output. I have attached the code:
using namespace std;
struct node
{
int data;
struct node *next;
}*new_node,*head,*tail,*temp,*ptr;
void create()
{
int i=1,value;
while(i==1)
{
new_node=(struct node*)malloc(sizeof(struct node));
printf("\nEnter value");
scanf("%d",&value);
new_node->data=value;
new_node->next=NULL;
if(head==NULL)
{
head=new_node;
tail=new_node;
}
else
{
tail->next=new_node;
tail=new_node;
}
printf("\nEnter 1 to continue and 0 to end");
scanf("%d",&i);
}
}
void create_2()
{
int i=1,value;
while(i==1)
{
new_node=(struct node*)malloc(sizeof(struct node));
printf("\nEnter value");
scanf("%d",&value);
new_node->data=value;
new_node->next=NULL;
if(head==NULL)
{
head=new_node;
tail=new_node;
}
else
{
new_node->next=head;
head=new_node;
}
printf("\nEnter 1 to continue and 0 to end");
scanf("%d",&i);
}
}
void display()
{
struct node *temp;
temp=head;
int value;
while(temp!=NULL)
{
printf("\n%d",value);
temp=temp->next;
}
}
void delete_first()
{
temp=head;
head=temp->next;
free(temp);
}
void delete_last()
{
ptr=head->next;
temp=head;
while(ptr->next!=NULL)
{
temp=temp->next;
ptr=ptr->next;
}
tail=temp;
free(ptr);
}
void delete_specified()
{
int value,pos;
printf("Enter Position");
scanf("%d",&pos);
ptr=head->next;
temp=head;
for(int i=1;i<pos;i++)
{
ptr=ptr->next;
temp=temp->next;
}
temp->next=ptr->next;
free(ptr);
}
void insert_start()
{
int value;
printf("\nEnter Value");
scanf("%d",&value);
new_node->data=value;
new_node->next=head;
head=new_node;
}
void insert_last()
{
int value;
printf("\nEnter Value");
scanf("%d",&value);
new_node->data=value;
tail->next=new_node;
tail=new_node;
}
void insert_specified()
{
int value,pos;
printf("\nEnter Value");
scanf("%d",&value);
printf("Enter Position");
scanf("%d",&pos);
new_node->data=value;
new_node->next=NULL;
ptr=head->next;
temp=head;
for(int i=1;i<pos;i++)
{
ptr=ptr->next;
temp=temp->next;
}
temp->next=new_node;
new_node->next=ptr;
}
int main()
{
void create();
void delete_specified();
void insert_specified();
return 0;
}