Page 145 - DCAP407_DATA_STRUCTURE
P. 145

Data Structure



                                                }
                                                 }
                                            }
                                            Output:
                                            1.  Insert at front end
                                            2.  Delete at rear end

                                            3.  Display
                                            4.  Exit
                                            1
                                            Enter the number to be inserted
                                            30
                                            1.  Insert at front end
                                            2.  Delete at rear end
                                            3.  Display

                                            4.  Exit
                                            1
                                            Enter the number to be inserted
                                            40
                                            1.  Insert at front end

                                            2.  Delete at rear end
                                            3.  Display
                                            4.  Exit
                                            3
                                            The contents of the queue is 30 40
                                            1.  Insert at front end
                                            2.  Delete at rear end
                                            3.  Display

                                            4.  Exit
                                            2
                                            The element deleted is 40
                                            In this example:
                                            1.  The header files are defined and a constant value 5 is defined for variable
                                                SIZE using #define header. The SIZE defines the size of the queue.
                                            2.  Four functions  are created namely,  Q_F(),  Q_E(),  front_insert(),
                                                rear_delete(), and  display().  The user has to select an appropriate
                                                function to be performed.
                                            3.  The switch statement is used to call the front_insert(), rear_delete(), and
                                                display() functions.
                                            4.  When the user enters 1, the  front_insert()  function is called. In the
                                                front_insert() function the if loop checks if the F pointer is equal to 0 or
                                                R  pointer is equal to  -1. If  the result is true,  then the  R  pointer  is



                          138                     LOVELY PROFESSIONAL UNIVERSITY
   140   141   142   143   144   145   146   147   148   149   150