Monday, 26 March 2018

Stack representation Using Array

Stack is a basic concept in Data Structure , It totally work on-
L: lAST
I: IN
F: FIRST
O: OUT

That means the last inserted element would be deleted first . So, here the program for the same

/* pre processor used throughout the program*/
#include<stdio.h>
#include<conio.h>
#define MAX 50

/*Some variable declared that we gonna used in the program*/
int stack[MAX],n,top,vk,i;

void push();     /*function for push the value in stack*/
void pop();       /*function for pop value from stack*/
void dsp();       /*function to display element in the stack*/

void main()
{
int po,pu;
clrscr();
top=-1;
printf("\nSpecify size for your stack:- ");
scanf("%d",&n);
printf("\n\nEnter no. of element you want to push:- ");
scanf("%d",&pu);
for(i=0;i<pu;i++)
{
push();
}
printf("\n\nDo you want to pop element (1--> Yes and 0-->No):- ");
scanf("%d",&po);
if(po==1)
{
pop();
}
dsp();
getch();
}

void push()
{
if(top>=n-1)
{
printf("\nStack is over flow");
}
else
{
printf("\n\tEnter a value to push:- ");
scanf("%d",&vk);
top++;
stack[top]=vk;
}
}

void pop()
{
if(top<=-1)
{
printf("\nStack is empty");
}
else
{
printf("\nPopped value:- %d",stack[top]);
top--;
}
}

void dsp()
{
if(top>=0)
{
for(i=top;i>=0;i--)
printf("\nOutput:- %d",stack[i]);
}
else
{
printf("\nSTACK IS EMPTY");
}
}


Saturday, 24 March 2018

Deletion at last in Singly Linked List

The deletion of linked list is come in 3 case :-
deletion at first
deletion at last
deletion at given point

But this time we are working on deletion at last .
So, here the code for the same hope so it will help you to understand it easily.

/*pre processor*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>

/*Structure of node */
struct node
{
int data;
struct node *ref;
};

/*function that we gonna use throughout the program */
void create(struct node **);
void display(struct node *);
void delast(struct node**);

void main()
{
struct node *head=NULL;
int num,i,l;
clrscr();
printf("\n\tEnter no. of element you want to insert:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
printf("\nDo You want any deletion at last(1-->Yes and 0-->No):- ");
scanf("%d",&l);
if(l==1)

delast(&head);
}
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node ));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;
}
}

void display(struct node *q)
{
while(q!=NULL)
{
printf("\n\tOUTPUT:- %d",q->data);
q=q->ref;
}
}

void delast(struct node **q)
{
struct node *temp=*q;
struct node *t;
if(temp->ref==NULL)
{
free(temp);
*q=NULL;
}
else
{       while(temp->ref!=NULL)
{
t=temp;
temp=temp->ref;
}

free(t->ref);
t->ref=NULL;
}
}


Friday, 23 March 2018

Deletion in Singly linked list at given point

In a linear data structure linked list is a basic program while study about Data Structure.
 So, this time we gonna do "Deletion in linked list at given position/ point"

/*Pre Processors used throughout the program*/
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>

/*structure of the node*/
struct node
{
int data;
struct node *ref;
};

/*function is created to handle program*/
void create(struct node **);
void display(struct node *);
void dellast(struct node**, int );

void main()
{
struct node *head=NULL;
int num,i,l,pos;
clrscr();
printf("\n\tEnter no. of element you want to insert:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
printf("\nDo You want any (1-->Yes and 0-->No):- ");
scanf("%d",&l);
if(l==1)
{       printf("\nEnter the position for the deletion :- ");
scanf("%d",&pos);
dellast(&head,pos);
}
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node ));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;
}
}

void display(struct node *q)
{
while(q!=NULL)
{
printf("\n\tOUTPUT:- %d",q->data);
q=q->ref;
}
}


void dellast(struct node **q, int pos)
{
int i;
struct node *next;
struct node *temp=*q;
if(*q==NULL)
{
return;
}

if(pos==0)
{
*q=temp->ref;
free(temp);
return;
}
for( i=1;temp!=NULL && i<pos-1;i++)
{
temp=temp->ref;
}
if(temp==NULL || temp->ref==NULL)
{
return;
}
next=temp->ref->ref;
free(temp->ref);
temp->ref=next;

}


Complete insertion Program for Singly Linked List (All cases)

In this program we gonna use all case of insertions in a singly linked list. In our previous programs , we do the same but separately here we gonna do all together.

/*Pre-Processors used throughout the program*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

/*structure of the node */
struct node
{
int data;
struct node *ref;
};

/*Functions used throughout the program*/
void create(struct node **);
void display(struct node *);
void addfirst(struct node **);
void addlast(struct node **);
void addmid(struct node **);

void main()
{
struct node *head=NULL;
int i,num;
clrscr();
printf("\nEnter no. of elements for your node:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
addfirst(&head);
addlast(&head);
addmid(&head);
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}

}

void display(struct node *p)
{
while(p!=NULL)
{
printf("\nOUTPUT:- %d",p->data);
p=p->ref;
}
}

void addfirst(struct node **q)
{
struct node *temp, *r;
temp=*q;
r=(struct node *)malloc(sizeof(struct node));
printf("\n\nEnter value for 1st element:- ");
scanf("%d",&r->data);
r->ref=temp;
*q=r;

}

void addlast(struct node **q)
{
struct node *temp, *l;
temp=*q;
l=(struct node *)malloc(sizeof(struct node));
printf("\n\nEnter value for last element:- ");
scanf("%d",&l->data);
l->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=l;

}

void addmid(struct node **q)
{
int i,position;
struct node *temp, *r;
r=(struct node *)malloc(sizeof(struct node));
if(r==NULL)
{
printf("\nUnable to allocate memory.");

}
else
{
printf("\nEnter the position:- ");
scanf("%d",&position);
printf("\n\nEnter value to be inserted at mid:- ");
scanf("%d",&r->data);
r->ref=NULL;
temp=*q;
for(i=2;i<=position-1;i++)
{
temp=temp->ref;
if(temp==NULL)
break;
}
if(temp!=NULL)
{
r->ref=temp->ref;
temp->ref=r;
printf("\nDATA INSERTED SUCCESSFULL");

}
else
{
printf("\nUNABLE TO INSERT DATA");
}
}
}


Thursday, 22 March 2018

Program to find greater no. out of 3

Program is simply created to find out the greatest  no.  out of three using C language.
so, here the code for the same.

/*Pre-Processor used throughout the program*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
        int a,b,c;
        clrscr();
        printf("\nEnter first element:- ");
        scanf("%d",&a);
   
        printf("\nEnter second element:- ");
        scanf("%d",&b);

        printf("\nEnter third element:- ");
        scanf("%d",&c);

        if(a>b&&a>c)
        {
                  printf("%d is greater among all of them",a);
         }
   
          if(b>c&&b>a)
          {
                  printf("%d is greater among all of them",b);
           }
     
           if(c>b&&c>a)
           {
                   printf("%d is greater among all of them",c);
            }
            getch();
}


Data Manipulation Language Short Note

                                                  DML(Data Manipulation Language)

DML deals with the record stored in the particular database.To know it in a better way some of the DDL Commands are below.

Commands:-

Insert
      Syntex:- Insert into <table_name> values(<all_attribute_records> );

Update
       Syntex:- Update <table_name> set <attribute_name>=<condition> where <attribute_name>=<>;

Delete
       Syntex:- Delete From <table_name> where <attribute_name>=<>;

Tuesday, 20 March 2018

Deletion of first node in Singly Linked List

In a simple linked list i.e is a part of a linear data structure we will know about how to delete the element in a linked list at a first node.
So, here the code for the deletion of first node in the linked list.


/*Pre-Processors*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

/*structure of your node*/
struct node
{
int data;
struct node *ref;
};

/*funtions to create a linked list , display , and delete the first node */
void create(struct node **);
void display(struct node *);
void delfirst(struct node **);

void main()
{
struct node *head=NULL;
int i,num, dlf;
clrscr();
printf("\n\tEnter no. of elements:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
printf("\n\tDo you want any deletion at first (1--> YES And 0-->NO):- ");
scanf("%d",&dlf);
if(dlf==1)
{
delfirst(&head);
}
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\n\n\tEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\n\tEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}
}

void display(struct node *q)
{
while(q!=NULL)
{
printf("\n\tOutput:-  %d",q->data);
q=q->ref;
}
}

void delfirst(struct node **q)
{
struct node *dlf;
int temp;
dlf=*q;
temp=dlf->data;
*q=dlf->ref;
free(dlf);
}


Array Program for Beginners

Array is a very important concept that we use in C . Basically it is a sequence of a data items of homogeneous values. Array as 1D is a base of whole array.
For sake of beginners here a simple program on array.

/* Pre- Processor used throughout the program*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 15   /* Length specified for MAX*/

void main()
{
int i, num, array[MAX];
clrscr();
printf("\nEnter no of element you want to insert in array: ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\nEnter a value:- ");
scanf("%d",&array[i]);
}
for(i=0;i<num;i++)
{
printf("\nOutput:- %d",array[i]);
}
getch();
}


Saturday, 17 March 2018

Average of all the elements in Array

Array is a must known concept through array we can perform many task or program.
So , an another program that will help you to understand array more easily.

/* Pre-Processors*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 25 /* Length of MAX*/


void main()
{
float array[MAX];
float i, num, sum=0;
float avg=0;
clrscr();
printf("\nEnter no. of Element for your array:- ");
scanf("%f",&num);
for(i=0;i<num;i++)
{
printf("\nEnter value:- ");
scanf("%f",&array[i]);

}
for(i=0;i<num;i++)
{
sum=sum+array[i];
}
avg=sum/num;
printf("\nAverage of the given values is %f",avg);
getch();
}



Friday, 16 March 2018

Bubble Sort in C

Bubble sort is a concept that we use to sorting of elements in ascending order . In C programming , their are many more technique that will do the same but according to the complexity of the program it is better upto some extends

/* Pre-Processors*/
#include<stdio.h>
#include<conio.h>
#define MAX 15 /* Length of MAX*/

void main()
{
    int array[MAX];
    int i, j, n, temp;

    printf("Enter no. of elements for array: ");
    scanf("%d", &n);
    printf("\nEnter the elements of array: \n");
    for (i = 0; i < n; i++)
    {
        scanf("%d", &array[i]);
    }

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < (n - i - 1); j++)
        {
            if (array[j] > array[j + 1])
            {
                temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
    printf("Array in Ascending...\n");
    for (i = 0; i < n; i++)
    {
        printf("%d\n", array[i]);
    }
    getch();
}


Matrix Multiplication in C

In C programming matrix is created by using 2D and 3D array but today we are working on matrix multiplication in C language.
Here the program to do Matrix Multiplication in C.

/* Pre-Processors */
#include <stdio.h>
#include<conio.h>
#define MAX 15 /*Length of MAX*/
int main()
{
  int m, n,i,j,k, sum = 0;
  int first[MAX][MAX], second[MAX][MAX], multiply[MAX][MAX];
  printf("Enter the number of rows and columns of first matrix\n");
  scanf("%d%d", &m, &n);
  printf("Enter the elements of first matrix\n");
 for (i = 0; i < m; i++)
    for (j = 0; j < n; j++)
      scanf("%d", &first[i][j]);
  printf("Enter the number of rows and columns of second matrix\n");
  scanf("%d%d", &m, &n);
printf("Enter the elements of second matrix\n");
 for (i = 0; i < m; i++)
      for (j = 0; j < n; j++)
        scanf("%d",&second[i][j]);
  for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < n; k++) {
          sum = sum + first[i][k]*second[k][j];
        }
 multiply[i][j] = sum;
        sum = 0;
      }
    }

    printf("Product of entered matrices:-\n");
 for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++)
        printf("%d\t", multiply[i][j]);
 printf("\n");
    }
 getch();
  return 0;
}

Addition of two matrix in C

In C Programming addition of matrix is all a very significant program while we are learning array in C.
So, here we gonna do Addition of matrix.

/*Pre-Processors */
#include<stdio.h>
#include<conio.h>
#define MAX 15 /* Length MAX*/
int main()
{
   int a[MAX][MAX], b[MAX][MAX], c[MAX][MAX];
   int i, j;
   int m,n;
   clrscr();
   printf("Enter no. of rows: ");
   scanf("%d",&m);
   printf("Enter no. of columns: ");
   scanf("%d",&n);

   printf("Enter elements of 1st matrix\n");
   for(i=0; i<m; ++i)
    for(j=0; j<n; ++j)
    {
       printf("Enter a%d%d: ", i+1, j+1);
       scanf("%d", &a[i][j]);
    }
   printf("Enter elements of 2nd matrix\n");
   for(i=0; i<m; ++i)
    for(j=0; j<n; ++j)
    {
       printf("Enter b%d%d: ", i+1, j+1);
       scanf("%d", &b[i][j]);
    }
   for(i=0; i<m; ++i)
    for(j=0; j<n; ++j)
    {
       c[i][j] = a[i][j] + b[i][j];
    }
   printf("\nSum Of Matrix:\n");

   for(i=0; i<m; ++i)
    for(j=0; j<n; ++j)
    {
       printf("%2d", c[i][j]);

       if(j==1)
          printf("\n");
    }
    getch();
return 0;
}

Matrix in C

In C language we can create a matrix by using 2D array. Array is a must known concept that we should know as it is used in many programs.

/* Pre- Processors*/
#include<stdio.h>
#include<conio.h>
#define MAX 15 /* Length of MAX*/

int main()
{
int j,i,m,n;
int a[MAX][MAX];
clrscr();
printf("\t\t\t\t----------------\n");
printf("\t\t\t\t--Array-Matrix--\n");
printf("\t\t\t\t----------------\n");
printf("Enter no. of elements for your Matrix:-");
printf("\n\nEnter no. of rows: ");
scanf("%d",&m);
printf("\nEnter no. of columns: ");
scanf("%d",&n);
printf("\nEnter values:-\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
getch();
return 0;
}


Thursday, 15 March 2018

Malloc --> Dynamic Memory Allocation (Addition of Elements)

Dynamic Memory Allocation is a concept of C language that will allow you to create space in memory at run time.
Types of Dynamic Memory Allocation:-
Calloc
Malloc

Here a  simple program of malloc that will make it easy to understand .

/* Pre-Processor*/
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,num,*ptr,sum=0;
    printf("Enter number of elements: ");
    scanf("%d",&num);
    ptr=(int *) malloc(num * sizeof(int));
    printf("Enter the elements of the array:-\n");
    for(i=0;i<num;i++)
    {
        scanf("%d",ptr+i);
        sum +=*(ptr+i);
    }
    printf("Sum=%d",sum);
    free(ptr);
}


Basic Turbo C/C++ Shortcut Keys

Turbo C/C++  Shortcut Keys:-

Turbo is a simple application software that is open source also i.e you can download it at free of cost and their is no license required for the same.

But here are some question raises that how can we cut , copy , paste , save, open and so on while working on the turbo C/C++.

So, here are the shortcut keys that an individual generally use while programming in C/C++ language.
  1. F1                                        Help
  2. F2                                        Save
  3. F3                                        Open
  4. F4                                        Go to Cursor
  5. F5                                        Zoom
  6. F6                                        Next
  7. F7                                        Trace into
  8. F8                                        Step over
  9. F9                                        Make
  10. F10                                      Menu
  11. ALT+X                                Quit
  12. ALT+Bksp                           Undo
  13. Shift+ALT+Bksp                 Redo
  14. Shift+Del                             Cut
  15. Ctrl+Ins                                Copy
  16. Shitf+Ins                              Paste
  17. Ctrl+Del                               Clear
  18. Ctrl+L                                   Seach Again
  19. Alt+F7                                  Previous Search
  20. Alt+F8                                  Next Error
  21. Ctrl+F9/Alt+R+Enter           Run
  22. Ctrl+F2                                 Program reset
  23. Alt+f9                                   Compile
  24. Alt+F4                                  Inspect
  25. Ctrl+F4                                 Evaluate or Modify
  26. Alt+F5                                  Output Screen
  27. Alt+Enter                              Toggle screen mode 

Insertion Sort Program (Ascending Order)

In C language we use various method for the sorting of elements but today we gonna work on Insertion sort that allows you to sort your elements in ascending order. The complexity in insertion sort is better than merge sort.
So, here the code for the same, hope so you will got the point.

/*Pre- Processors used throughout the program*/
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>

#define MAX 25 /*Length for MAX*/

void main()
{
int num, a[MAX], temp ,i ,j; /*Declaration of variables*/
clrscr(); /*Clears the output screen*/
printf("Enter no. of elements for your list:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<num;i++)
{
temp=a[i];
j=i-1;
while(temp<a[j]&&j>=0)
{
a[j+1]=a[j];
--j;
}
a[j+1]=temp;
}
printf("\nSorted List:- \n");
for(i=0;i<num;i++)
{
printf("%d\n",a[i]);

}

getch();
}


ALL Case of Deletion in Linked List

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

struct node
{
int data;
struct node *ref;
};

void create(struct node **);
void display(struct node *);
void del(struct node **);

void main()
{
struct node *head=NULL;
int i,num;
clrscr();
printf("\nEnter no. of elements for your node:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
        del(&head);
        display(head);
        getch();
  }

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}

}

void display(struct node *p)
{
while(p!=NULL)
{
printf("\nOUTPUT:- %d",p->data);
p=p->ref;
}
}

void del(struct node **q)
{
struct node *temp , *old ;
int i,j=0;
temp = *q ;
old = temp ;
printf("\n\nEnter the number of position of element which you want to delete :   ");
scanf("%d",&i);

if(*q!=NULL && i==1)
{
old = old->ref ;
temp = old ;
*q = temp ;
}
      if(*q==NULL)
      {
old = old->ref;
temp = old ;
*q = temp ;
      }
      else
      {
while(j<i)
{
j++ ;
old = old->ref ;
if(j==i-1)
break ;
temp = temp->ref ;
}
temp->ref = old->ref ;
       }
}




Tuesday, 13 March 2018

Insertion at Middle in Singly Linked List

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

struct node
{
int data;
struct node *ref;
};

void create(struct node **);
void addmid(struct node **);
void display(struct node *);

void main()
{
struct node *head=NULL;
int i,num;
clrscr();
printf("\nEnter no. of elements for your node:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
addmid(&head);
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}

}

void display(struct node *p)
{
while(p!=NULL)
{
printf("\nOUTPUT:- %d",p->data);
p=p->ref;
}
}

void addmid(struct node **q)
{
int i,position;
struct node *temp, *r;
r=(struct node *)malloc(sizeof(struct node));
if(r==NULL)
{
printf("\nUnable to allocate memory.");

}
else
{
printf("\nEnter the position:- ");
scanf("%d",&position);
printf("\n\nEnter value to be inserted at mid:- ");
scanf("%d",&r->data);
r->ref=NULL;
temp=*q;
for(i=2;i<=position-1;i++)
{
temp=temp->ref;
if(temp==NULL)
break;
}
if(temp!=NULL)
{
r->ref=temp->ref;
temp->ref=r;
printf("\nDATA INSERTED SUCCESSFULL");

}
else
{
printf("\nUNABLE TO INSERT DATA");
}
}
}


Insertion at last in Linked List

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

struct node
{
int data;
struct node *ref;
};

void create(struct node **);
void display(struct node *);
void addlast(struct node **);

void main()
{
struct node *head=NULL;
int i,num;
clrscr();
printf("\nEnter no. of elements for your node:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
addlast(&head);
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}

}

void display(struct node *p)
{
while(p!=NULL)
{
printf("\nOUTPUT:- %d",p->data);
p=p->ref;
}
}

void addlast(struct node **q)
{
struct node *temp, *l;
temp=*q;
l=(struct node *)malloc(sizeof(struct node));
printf("\n\nEnter value for last element:- ");
scanf("%d",&l->data);
l->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=l;

}


Insertion at first in Singly Linked List

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<malloc.h>

struct node
{
int data;
struct node *ref;
};

void create(struct node **);
void display(struct node *);
void addfirst(struct node **);


void main()
{
struct node *head=NULL;
int i,num;
clrscr();
printf("\nEnter no. of elements for your node:- ");
scanf("%d",&num);
for(i=0;i<num;i++)
{
create(&head);
}
addfirst(&head);
display(head);
getch();
}

void create(struct node **q)
{
struct node *temp, *r;
temp=*q;
if(*q==NULL)
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&temp->data);
temp->ref=NULL;
*q=temp;
}
else
{
r=(struct node *)malloc(sizeof(struct node));
printf("\nEnter value:- ");
scanf("%d",&r->data);
r->ref=NULL;
while(temp->ref!=NULL)
{
temp=temp->ref;
}
temp->ref=r;

}

}

void display(struct node *p)
{
while(p!=NULL)
{
printf("\nOUTPUT:- %d",p->data);
p=p->ref;
}
}

void addfirst(struct node **q)
{
struct node *temp, *r;
temp=*q;
r=(struct node *)malloc(sizeof(struct node));
printf("\n\nEnter value for 1st element:- ");
scanf("%d",&r->data);
r->ref=temp;
*q=r;

}