Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code which does three options. how can i add two more options which

ID: 666820 • Letter: I

Question

I have this code which does three options.

how can i add two more options which are: 1-print the last letter: 2-print the frist letter:

#include <stdio.h>
#include <stdlib.h>
#include "function.h"

int main()

{
  


   int option = 0;
   char letter;

       printf(" Queue options: 1. insert an item 2.remove an item 3. exit Option number? ");
       scanf("%d", &option);
              
       while(option <=3) {

           switch ( option )
           {
           case 1:
           //insert an item
                {
                printf("A character? ");
               scanf("%s", &letter);
               printf(" ");
               insert(letter);
       printf(" Queue options: 1. insert an item 2.remove an item 3. exit Option number? ");
       scanf("%d", &option);
               break;
                }

           case 2:{
            //remove an item
           remove1();
printf(" Queue options: 1. insert an item 2.remove an item 3. exit Option number? ");
       scanf("%d", &option);   
           break;}
           case 3:
                        {printf("No more fun with queue? bye bye ");
           exit(0);}
           break;
           default:
               {
            printf("Invalid option Queue options: 1. insert an item 2.remove an item 3. exit Option number?");
               }
           }

       }  


  
   return 0;
}

Explanation / Answer

You can add following two functions in your code to print first and last letter from the queue: typedef struct { int dataitem; struct listelement *link; } listelement; listpointer = (struct listelement *) malloc (sizeof (listelement)); void Print_First_Letter (listelement * listpointer) { if (listpointer == NULL) printf ("queue is empty! "); else printf ("%d ", listpointer -> dataitem); printf (" "); } void Print_Last_Letter (listelement * listpointer) { if (listpointer == NULL) printf ("queue is empty! "); else while (listpointer != NULL) { listpointer = listpointer -> link; } printf ("%d ", listpointer -> dataitem); printf (" "); }