Skip to main content

Linked List

 



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


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

void display(struct node *ptr){
    while(ptr!=NULL){
        printf(" %d ",ptr->data);
        ptr = ptr->link;
    }
}
int main()
{

    struct node *a;
    struct node *b;
    struct node *c;
    struct node *d;
   
    a = malloc(sizeof(struct node));
    b = malloc(sizeof(struct node));
    c = malloc(sizeof(struct node));
    d = malloc(sizeof(struct node));
   

    a->data = 1;
    a->link = b;

    b->data = 2;
    b->link = c;

    c->data = 3;
    c->link = d;

    d->data = 4;
    d->link = NULL;


   


display(a);

   
    return 0;
}


Comments