Insert New Node at begining of Linked List

In order to insert a new node at the beginning of the list we have to follows the below steps:
(1) First we have to check weather free node is available in the Availability Stack or not. If free node is available then we can allocate memory to new node.
(2) After creating new node we have to check weather linked list is empty or not. We have two possibilities:
(A) Linked List is empty (FIRST=NULL). In this case the newly created node becomes the first node of linked list.
(B) Linked List is not empty (FIRST ≠ NULL). In this case we can insert new node at the beginning of linked list. Now new node becomes the first node.

Algorithm to Insert New Node at begining of Linked List

Step 1: If AVAIL=NULL then
Write “Availability Stack is Empty”
Else
NEW_NODE=AVAIL
Step 2: If FIRST = NULL then
NEW_NODE -> INFO = X
FIRST = NEW_NODE
Else
NEW_NODE -> INFO = X
FIRST = NEW_NODE
Step 3: Exit

Program to Insert New Node at begining of Linked List

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int info;
};
struct node *FIRST;
void createlist()
{
char ch;
printf("Enter n for break\n");
ch=getchar();
while(ch!='n')
{
struct node *NEW_NODE,*SAVE;int x;
NEW_NODE=(struct node *)malloc(sizeof(struct   node));
printf("Enter Data:");
scanf("%d",&x);
NEW_NODE->info=x;
if(FIRST==NULL)
{
FIRST=NEW_NODE;
}
else
{
SAVE=FIRST;
{
}
}
fflush(stdin);
printf("Enter n for break\n");
ch=getchar();
}
}
void insertbeg()
{
struct node *NEW_NODE;
int x;
NEW_NODE=(struct node *)malloc(sizeof(struct node));
printf("Enter value of node:");
scanf("%d",&x);
NEW_NODE->info=x;
if(FIRST==NULL)
{
FIRST=NEW_NODE;
}
else
{
FIRST=NEW_NODE;
}
printf("%d is succesfully inserted\n",x);
return;
}
void display()
{
struct node *SAVE;
if(FIRST==NULL)
{
return;
}
printf("elements are:\n");
SAVE=FIRST;
while(SAVE!=NULL)
{
printf("|%d|",SAVE->info);
else
printf("|%d|->",SAVE->info);
}
printf("\n");
return;
}
void main()
{
clrscr();
FIRST=NULL;
createlist();
display();
insertbeg();
display();
getch();
}