|
|
|
|||
Fig 3. add() operation of linked list Following is the crux of this add() operation : Firstly, it makes a new node by calling Node class constructor. Inserts the value into the node by calling the set method e.g. value 2 is inserted into the node. Now if the list already exists (has some elements inside or its size is non-zero), it inserts the node after the current position. If the list does not already exist, this node is added as the first element inside the list. Let’s try to add few more elements into the above linked list in the figure. The following are the lines of code to be executed to add nodes with values 8, 7 and 1 into the linked list. Fig 4. More elements added to linked list |
|||||
|
BACK |
HOME |
NEXT |
||