-
addition in linked lists
How can i make addition in my linked lists if the nodes are stroing two values:
1) int element
2) int colomnvalue
i have to make the addition on the basis that the nodes having the same colomvalue, thier element should be added.
This addition is to be made in linked lists either by creating new linked lists or other way.. i am trying to make the logic but it stops on one or other way.
-
Create a function called initialiseNode, which takes your data values as parameters.
It allocates the memory for a node, initialises all the pointers, and assigns the parameter values to the data portion of the node.
You then pass this constructed node to one of your list insertion functions.
If your list has both 'head' and 'tail' pointers, then it is very easy.
To prepend to the start of the list, it's simply
node->next = head;
head = node;
To append to the end of the list,
tail->next = node;
tail = node;