0

How to print the nodes this linked list?

#include<stdio.h> #include<stdlib.h> struct Node {     int data;     struct node *agla; }; int  create(int member) {    int i,j;    struct Node* temp;    struct Node* HOME=NULL;    temp=(struct Node*)malloc(sizeof(struct Node));    temp->data=member;    if(HOME==NULL)    {        HOME=temp;    HOME->agla=temp;    }    else{         temp->agla=temp;    } //j=show(struct node ) } int main() { int i=0,num,member,j,k; printf("\n enter the num" ); scanf("%d",&num);    printf("\n enter the members\n");    while(i<num)    {        scanf("%d",&member);        create(member);        i++;    }    printf("\n linked list has been created"); }

16th Nov 2018, 2:18 PM
Shashank Singh
Shashank Singh - avatar
1 Réponse
+ 1
You cannot print it, because you never saved pointer to first element which we should start iterating from. Btw. you just create set of pointers, none of them are linked to one another, hence it's not linked list. You can see my doubly circular linked list in my codes, and base yours on it.
16th Nov 2018, 2:30 PM
Jakub Stasiak
Jakub Stasiak - avatar