Page 117 - DCAP407_DATA_STRUCTURE
P. 117

Data Structure



                                          }
                                          Output:
                                          1. Insert at beginning
                                          2. Display

                                          3. Exit
                                          Enter the choice
                                          1
                                          Enter the number to be inserted
                                          50
                                          1. Insert at beginning
                                          2. Display
                                          3. Exit

                                          Enter the choice
                                          2
                                          Contents of the list:
                                          50
                                          1. Insert at beginning
                                          2. Display

                                          3. Exit
                                          Enter the choice
                                          1
                                          Enter the number to be inserted
                                          40
                                          1. Insert at beginning
                                          2. Display

                                          3. Exit
                                          Enter the choice
                                          2
                                          Contents of the list:
                                          40
                                          50

                                          In this example:
                                          1.   A structure named list is created with a data field named value and link
                                               field named *link.
                                          2.   Three  functions are  created namely,  insert_beginning(),  display(),  and
                                               exit. The user has to select the appropriate function to perform.

                                          3.   The function getnode() creates and allocates memory for first node. If the
                                               memory allocation is unsuccessful, then the function displays  a message
                                               “out of memory”.



                          110                     LOVELY PROFESSIONAL UNIVERSITY
   112   113   114   115   116   117   118   119   120   121   122