BASIC LINK LIST

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
void main()
{
struct node *head=NULL,*one,*two,*three,*ptr;//declare link list variables
clrscr();
cout<<"LINKED LIST PROGRAM\n";
one=NULL; //initialise null
two=NULL;
//using c++ based
one=new node();
two=new node();
three=new node();//use new with dataype of structure
     //using c then memory will be allocated this way one=(struct node*)malloc(sizeof(struct node));//allocate memory
      // two=(struct node*)malloc(sizeof(struct node));
       //  three=(struct node*)malloc(sizeof(struct node));
one->data=1;
one->next=two;
two->data=2;
two->next=three;
three->data=3;
three->next=NULL;
head=one;//link the start from all the list
ptr=head;//keeping address of first node in ptr
//cout<<one->data<<two->data<<three->data;
while(ptr!=NULL)//
{
   cout<<" "<<ptr->data;
   ptr=ptr->next;
}
getch();
}