#include #include struct node { int data; struct node *link; }*x,*first,*y; //Structure of the NODE of LL void opt(); // Displays the Options to User void reading(); // Reads the input and Instantaneouly Stuffs the input when cndtion applicable void check(int *); // Checks if the no. of 1 in copunt has reached 5 consecutively void display(); // Displasyt the Stuffed Information on screen extracting frm the LL void main() { int option=0; // Choice x=first; //Initialising to First node while(option!=3) //Repeat until chosen 3 for exit { opt(); scanf("%d",&option); switch(option) { case 1: reading(); break; case 2: display(); break; case 3: break; default: printf("\nINVALID OPTION\n"); } } } void opt() { printf("\nEnter your Choice\n\n"); printf("1.Read data and stuff it\n"); printf("2.Display Stuffed Data\n"); printf("3.EXIT\n\n"); } void reading() { int a,count=0; y->link=x; while((a=atoi(getchar()))==1 || a==0) /* reads char converts to int and checks if 1 or 0 and repeats till some other value inserted*/ { if(a==1 && y->link==x) // if 1 and previous node data also 1 then do the following { count++; // if consecuytive 1 then incrementing the count x->data=a; // putting the read data in NODE y=x; // Backing up previous one for cheicing if consecutive x->link=(struct node *)malloc(sizeof(struct node)); //Creatng new node x=x->link; // moving current Poinetr to new check(&count); //checking if consecutive 5 ones are reacehd so that Stiffiung can be done } else // if condition not satisfied even then addingto LIST { count=0; //resetting the count coz not consecutive 1s x->data=a; //adding in list x->link=(struct node *)malloc(sizeof(struct node)); x=x->link; } } if(a==9) // 9 is for ending the INPUT..when 9 entered shud stop reading input x=NULL; // for pointing as the lastnode for DISPLAY function condition else printf("\n\nEntered Invalid Data.Re-Enter Data only 0 and 1.\n\n"); } void check(int *ct) { if(*ct==5) //if count == 5 time 1 then add a node with a 0 in it and create another link abd reset the count { x->data=0; x->link=(struct node *)malloc(sizeof(struct node)); x=x->link; ct=0; } } void display() { y=first; printf("\nStuffed Data is \n\n"); while(y->link!=NULL) //travesring form first to last node { printf("%d",y->data); y=y->link; } }