Showing posts with label Sum Linked List. Show all posts
Showing posts with label Sum Linked List. Show all posts

Wednesday, December 18, 2013

Adding 3 Linked Lists


Last Time we discussed the basics of Linked List Today we will try adding more more than 2 Linked Lists. Although in the program you will see that I have manually created Lists and then adding them in a very constrained manner which can be overcome by introducing dynamic looping as per the program requirements.


#include <stdio.h>
#include <stdlib.h>

struct Node
{
    int info;
    struct Node* next;
};

int lenghtOfLinkedList(struct Node*); // This method is count the number of elements in a list and on the basis of max count neutralize all other to bring them to the format of largest one.
void createLinkedListA(struct Node*); // create a sample linked list
void createLinkedListB(struct Node*); // create a sample linked list
void createLinkedListC(struct Node*); // create a sample linked list

Now we have linked lists
A = head->6->7->8->9
B = head->1->2->3
c = head->4->5

void neutralizeLinkedList(struct Node*, int, int); 


Now after neutralizing we have linked lists
A = head->6->7->8->9
B = head->0->1->2->3
C = head->0->0->4->5