Linked List Rudimentary Operations

 

  The linked list data structure provides operations to work on the nodes inside the list.

The first operation we are going to discuss here is to create a new node in the memory. The Add(9) is used to create a new node in the memory at the current position to hold ‘9’. You must remember while working with arrays, to add an element at the current position that all the elements after the current position were shifted to the right and then the element was added to the empty slot.

Here, we are talking about the internal representation of the list using linked list. Its interface will remain the same as in case of arrays.

We can create a new node in the following manner in the add() operation of the linked list with code in C++:

Node *    newNode   =   new    Node(9);

The first part of the statement that is on the left of the assignment is declaring a variable pointer of type Node. It may also be written as Node   * newNode. On the right of this statement, the new operator is used to create a new Node object as new Node(9). This is one way in C++ to create objects of classes. The name of the class is provided with the new operator that causes the constructor of the class to be called. The constructor of a class has the same name as the class and as this a function, parameters can also be passed to it. In this case, the constructor of the Node class is called and ‘9’ is passed to it as an int parameter. 

 

BACK

HOME

NEXT