Linked List class 1

 // Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;


struct node{

    public:

    int data;

    node* next;

    

    node(int data){

        this->data=data;

        next=NULL;

    }

};


void display(node* head){

    node* temp=head;

    while(temp!=NULL){

        cout<<temp->data<<" ";

        temp=temp->next;

    }

    

    temp=head;

    while(temp!=NULL){

        cout<<temp->data<<" ";

        temp=temp->next;

    }

    

}


int main() {

    node n1(1);

    node n2(2);

    node n3(3);

    node n4(4);

    node n5(5);

    node*head=&n1;

    n1.next=&n2;

    n2.next=&n3;

    n3.next=&n4;

    n4.next=&n5;

    

    

   

    display(head);

    

    

    

    


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings