Linked List Create and Traversal

 #include<bits/stdc++.h>

using namespace std;

struct Node{

    int data;

    struct Node *Next;

};

int main()

{


    struct Node *a;

    struct Node *b;

    struct Node *c;

    a=(struct Node *)malloc(sizeof(struct Node));

    b=(struct Node *)malloc(sizeof(struct Node));

    c=(struct Node *)malloc(sizeof(struct Node));

    a->data=10;

    b->data=20;

    c->data=30;

    a->Next=b;

    b->Next=c;

    c->Next=NULL;

    while(a!=NULL){

        cout<<a->data<<endl;

        a=a->Next;

    }

}


Comments