New course! Every coder should learn Generative AI!
Try a free lesson0
There's nothing in the output. Only blinking cursor.
#include<stdio.h> #include<stdlib.h> struct node { int rno; struct node *next; }; void main() { int n,i,r; struct node *head; //head=(struct node *)malloc(sizeof(struct node)); head=NULL; //scanf("%d",&n); n=5; for(i=1;i<=n;++i) { r=i; //scanf("%d",&r); if(head==NULL) { head=(struct node *)malloc(sizeof(struct node)); head->rno=r; head->next=NULL; } struct node *tmp; tmp=head; int f=0; while(tmp!=NULL) { if(tmp->rno==r) { f=1; break; } tmp=tmp->next; } if(f=0) { tmp->nex
4 Answers
+ 2
Before creating a new node you should traverse list to check existing value.
If there is no such value then create a new node, set its next member to head value, and set head to new node address:
https://code.sololearn.com/cwvgqrjmmRyn
+ 1
https://code.sololearn.com/cuKVKOfYVfvG/?ref=app
+ 1
The code is attached
0
Why your main is void
any remove comments
https://code.sololearn.com/cLTyWsNUMZMG/?ref=app