(HackerRank)Write a modular C program using Circular Singly Linked List to read and display all the web series details
Brad Pitt acted in many Hollywood movies and web series. He has many web series popular over the internet. Write a modular C program using Circular Singly Linked List to read and display all the web series details. Also Count and Display the web series details of a particular year.
Input Format
First line indicates N, number of web series.
Second line onwards details of web series.
Last Line is particular year.
Constraints
N should be positive.
Output Format
Display all the web series details.
Display web series of particular year.
Display count of web series of particular year.
Sample Input 0
4
Friends 1994
BurnAfterReading 2008
Boffo 2006
GloryDays 1990
2008
Sample Output 0
Friends 1994
BurnAfterReading 2008
Boffo 2006
GloryDays 1990
BurnAfterReading 2008
1
Sample Input 1
3
BurnAfterReading 2008
Boffo 2006
GloryDays 1990
2000
Sample Output 1
BurnAfterReading 2008
Boffo 2006
GloryDays 1990
0
CODE:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> struct node { char ws[30]; int yr; struct node *link; }; typedef struct node *NODE; NODE newnode,cur; NODE createnode(); NODE insert_e(NODE tail); void display(NODE tail); NODE count_a(NODE tail); NODE tail=NULL; int main() { int i,n; scanf("%d",&n); if(n>0) { for(i=0;i<n;i++) { tail=insert_e(tail); } display(tail); tail=count_a(tail); } else { exit(0); } return 0; } void display(NODE tail) { cur=tail->link; while(cur!=tail) { printf("%s %d",cur->ws,cur->yr); printf("\n"); cur=cur->link; } printf("%s %d",tail->ws,tail->yr); printf("\n"); } NODE createnode() { newnode=(NODE)malloc(sizeof(struct node)); if(newnode==NULL) { exit(0); } scanf("%s %d",newnode->ws,&newnode->yr); newnode->link=newnode; return newnode; } NODE insert_e(NODE tail) { newnode=createnode(); if(tail==NULL) { tail=newnode; } else { newnode->link=tail->link; tail->link=newnode; tail=newnode; } return tail; } NODE count_a(NODE tail) { int k,count=0; scanf("%d",&k); cur=tail->link; printf("\n"); while(cur!=tail) { if(cur->yr==k) { count++; printf("%s %d\n",cur->ws,cur->yr); } cur=cur->link; } if(tail->yr==k) { count++; printf("%s %d\n",tail->ws,tail->yr); } if(count!=0) printf("\n"); printf("%d",count); return tail; }
OUTPUT
Congratulations, you passed the sample test case. Click the Submit Code button to run your code against all the test cases. Input (stdin) 4 Friends 1994 BurnAfterReading 2008 Boffo 2006 GloryDays 1990 2008 Your Output (stdout) Friends 1994 BurnAfterReading 2008 Boffo 2006 GloryDays 1990 BurnAfterReading 2008 1 Expected Output Friends 1994 BurnAfterReading 2008 Boffo 2006 GloryDays 1990 BurnAfterReading 2008 1
Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:
Top 100+ C Programming codes – KLE Technological University