Untitled
// Online C compiler to run C program online #include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }*start=NULL; void createll(struct node **start, int data) { struct node *ptr = (struct node *)malloc(sizeof(struct node)); ptr->data = data; ptr->next = NULL; if (*start == NULL) *start = ptr; else { struct node *temp = *start; while (temp->next != NULL){ temp = temp->next; } temp->next = ptr; } } void printll(struct node **start){ if (*start==NULL){ printf("Empty list"); } else{ struct node *temp=*start; while(temp!=NULL){ printf("%d",temp->data); temp=temp->next; printf("\n"); } } } void main() { int k; scanf("%d",&k); while(k!=0){ int data; printf("enter data"); scanf("%d",data); createll(&start,data); k--; } printll(*start); }
Leave a Comment