Dynamic Linked List_1

 avatar
kaziamir
c_cpp
a year ago
588 B
13
Indexable
Never
#include<bits/stdc++.h>
#include<stdbool.h>
using namespace std;

#define resetP p = start;

typedef struct node{
    int data;
    node *next;
}node;

int main(){
    int n;
    cin>>n;
    node *nodes[n];
    for(int i=0;i<n;i++){
        nodes[i] = (node *)malloc(sizeof(node));
        cin>>nodes[i]->data;
    }
    node *start = nodes[0];
    node *p = start;

    for(int i=0;i<n;i++){
        //if(i==n-1)  nodes[i]->next= NULL;
        nodes[i]->next = nodes[i+1];
    }

    resetP;
    while(p != NULL){
        cout<<p->data<<endl;
        p = p->next;
    }

    return 0;
}