Page 109 - DCAP407_DATA_STRUCTURE
P. 109

Data Structure



                                          The created linked list is:
                                          Node1: 40
                                          Node2: 50
                                          Menu

                                          1.  Create node
                                          2.  Display
                                          3.  Insert node at the beginning
                                          4.  Exit
                                          Enter your choice:
                                          2
                                          The linked list is:
                                          Node1: 40

                                          Node2: 50
                                          Menu
                                          1.  Create node
                                          2.  Display
                                          3.  Insert node at the beginning
                                          4.  Exit

                                          Enter your choice:
                                          3
                                          Enter the number to be inserted: 60
                                          After insertion at the beginning, the list is:
                                          Node1: 60
                                          Node2: 40
                                          Node3: 50

                                          In this example:
                                          1.  A list is created with a data field named value and link field named *next.
                                          2.  Three pointers are created namely, HEAD, PTR and newnode. HEAD points
                                              to the first node, PTR points to the next element, and newnode signifies the
                                              new node yet to be created.
                                          3.  Four functions are created namely,  menu(),  createnode(),  display(),
                                              emptylist(),  and  insert_beg(). The function  menu()  displays the operations
                                              that a user can perform. The operations are:
                                              (a)  Creating a node
                                              (b)  Displaying the list items
                                              (c)  Inserting a node at the beginning of the list
                                              When the user tries to display an empty list,  the function  emptylist()  is
                                              called.






                          102                     LOVELY PROFESSIONAL UNIVERSITY
   104   105   106   107   108   109   110   111   112   113   114