Header Ads Widget

Responsive Advertisement

Link List Creation And Traversal & Print

 



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

struct Node
{
    int data;
    struct Node *next;
};

void link_list_Traversal_print(struct Node *ptr)
{
    while (ptr != NULL)
    {
        printf("Element : %d\n", ptr->data);
        ptr = ptr->next;
    }
}

int main()
{
    struct Node *head;
    struct Node *secoond;
    struct Node *third;
    struct Node *fourth;
    struct Node *fifth;

    head = (struct Node *)malloc(sizeof(struct Node));
    secoond = (struct Node *)malloc(sizeof(struct Node));
    third = (struct Node *)malloc(sizeof(struct Node));
    fourth = (struct Node *)malloc(sizeof(struct Node));
    fifth = (struct Node *)malloc(sizeof(struct Node));

    head->data = 11;
    head->next = secoond;

    secoond->data = 85;
    secoond->next = third;

    third->data = 63;
    third->next = fourth;

    fourth->data = 25;
    fourth->next = fifth;

    fifth->data = 45;
    fifth->next = NULL;

    link_list_Traversal_print(head);

    return 0;
}

Post a Comment

0 Comments