Page 18 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 18

Unit 1: Introduction to Data Structure and Arrays




                                                                                                Notes
                                          Figure 1.3: Node
                                  node


                                   item        next


          Such structures, which contain a member field that points to the same structure type, are called
          self-referential structures. A node may be represented in general form as follows:
                                Figure 1.4: Structure Declaration for the Node

                                       struct label-name
                                       {
                                              type   member1;
                                              type   member2;
                                              type   member3;
                                              .   .   .     .
                                              .   .   .     .
                                              struct   label-name *next;
                                       };

          The node may contain more than one item with different data types. However, one of the items
          must be a pointer of the type label-name. The above node with all its members can be depicted
          as follows:



                 member1     member2                         membern     next



                                             node

          Consider a simple example to understand the concept of linking. Suppose we defi ne a structure
          as follows:
          struct list
          {
          int value;
          struct list *next;
          };
          Assume that the list contains two node viz. node1 and node2. They are of type struct list and are
          defined as follows:

          struct list node1,node2;















                                           LOVELY PROFESSIONAL UNIVERSITY                                    13
   13   14   15   16   17   18   19   20   21   22   23