The Question is:
Create a bidirectional linked list of FM stations (mentioned below) using C. Then set pointer to first station. Take user input: Enter 1 to play next station Enter 2 to play previous station Enter 3 to play first station Enter 4 to exit
The linked list for FM station related data should be:
Station 1          Radio_City             91.1
Station 2          Radio_One             91.8
Station 3          BIG_FM                  92.7
Station 4          RED_FM                 93.5
Station 5          My_FM                   94.3
Station 6          Hit_FM                    95.0
Station 7          Radio_Mirchi          98.3
Station 8          Vividh_Bharti          100.1
Station 9          Gyan_Vani               105.6
Station 10        Radio_Dhamal        106.4
Station 11        DD_News                108.2
Station 12        Gyan_Ganga           109.6
The code that I have written is:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct Node
{
    int sno;
    char sname[50];
    float sfreq;
    struct Node *Lnext,*Rnext;
};
struct Node *createnewnode()
{
    int n;
    struct Node *first,*last;
    printf("\n Enter the number of stations available:");
    scanf("%d",&n);
    first=(struct Node*)malloc(sizeof(struct Node));
    printf("\nEnter the Station number: ");
    scanf("%d",&first->sno);
    printf("Enter the Station Name: ");
    fflush(stdin);
    scanf("%s",first->sname);
    printf("Enter the station Frequency: ");
    scanf("%f",&first->sfreq);
    last=first;
    last->Lnext=NULL;
    last->Rnext=NULL;
  
    int i=2;
    while(i<=n)
    {
        struct Node *temp=(struct Node*)malloc(sizeof(struct Node));
        printf("\nEnter the Station number: ");
        scanf("%d",&temp->sno);
        printf("Enter the station name: ");
        fflush(stdin);
        scanf("%s",temp->sname);
        printf("Enter the station frequency: ");
        scanf("%f",&temp->sfreq);
        
        temp->Lnext=last;
        last->Rnext=temp;
        last=last->Rnext;
        last->Rnext=NULL;
        
        i++;
    }
    return first;
}
void display_by_position(struct Node *first)
{
    struct Node *temp=first;
    printf("\n The list of stations is....\n");
    if(temp==NULL)
    {
        printf("\nThere are no stations to display");
        return;
    }
    else
    {
        printf("\n\tSTATION NUMBER\t\tSTATION NAME\t\tSTATION FREQUENCY");
        for(temp=first;temp!=NULL;temp=temp->Rnext)
        {
            printf("\n\t%d\t\t\t%s\t\t\t%.1f",temp->sno,temp->sname,temp->sfreq);
        }
    }
    
    int choice;
    while(choice!=4)
    {
        printf("\n-------------------------------------------\n");
        printf("\nEnter \"1\" to play the next station");
        printf("\nEnter \"2\" to play the previous station");
        printf("\nEnter \"3\" to play the first station");
        printf("\nEnter \"4\" to exit");
        printf("\n-------------------------------------------\n");
        printf("\nEnter your choice: ");
        scanf("%d",&choice);
        
        if(choice==1)
        {
            if(temp->Rnext==NULL)
            printf("\nThis is the last station\n");
            else
            {
                temp=temp->Rnext;
                printf("\n The next station is...\n");
                printf("\nStationNumber:  %d      %s      %f\n",temp->sno,temp->sname,temp->sfreq);
            }
        }
        
        else if(choice==2)
        {
            if(temp->Lnext==NULL)
            printf("\nThe is the first station");
            else
            {
                temp=temp->Lnext;
                printf(" \n The previous station is...\n");
                printf("\nStationNumber:  %d      %s      %f\n",temp->sno,temp->sname,temp->sfreq);
            }
        }
        
        else if(choice==3)
        {
            temp=first;
            printf("\n The first station in the list is...\n");
            printf("\nStationNumber:  %d      %s      %f\n",temp->sno,temp->sname,temp->sfreq);
        }
        
        else if(choice==4)
        {
            printf("\n Thank you for your patience...");
        }
        
        else
        {
            printf("\n Invalid choice...");
        }
    }
}
int main()
{
    struct Node *p=createnewnode();
    display_by_position(p);
    return 0;
}
In this code, the program gets terminated when the user gives input as '1' to play the next station. Similarly, the program gets terminated for whatever input the user gives
 
    