# Generalized Linked List

A Generalized Linked List L, is defined as a finite sequence of n>=0 elements, l_{1}, l_{2}, l_{3}, l_{4}, …, l_{n}, such that l_{i} are either atom or the list of atoms. Thus

**L = (l _{1}, l_{2}, l_{3}, l_{4}, …, l_{n})**

where n is total number of nodes in the list.

To represent a list of items there are certain assumptions about the node structure.

- Flag = 1 implies that
*down pointer*exists - Flag = 0 implies that
*next pointer*exists - Data means the atom
- Down pointer is the address of node which is down of the current node
- Next pointer is the address of node which is attached as the next node

**Why Generalized Linked List?**

Generalized linked lists are used because although the efficiency of polynomial operations using linked list is good but still, the disadvantage is that the linked list is unable to use *multiple variable polynomial equation* efficiently. It helps us to represent multi-variable polynomial along with the list of elements.

**Typical ‘C’ structure of Generalized Linked List**

`typedef` `struct` `node { ` ` ` `char` `c; ` `//Data ` ` ` `int` `index; ` `//Flag ` ` ` `struct` `node *next, *down; ` `//Next & Down pointer ` `}GLL; ` |

*chevron_right*

*filter_none*

**Example of GLL** {List representation}

*( a, (b, c), d)*

When first field is 0, it indicates that the second field is variable. If first field is 1 means the second field is a down pointer, means some list is starting.

**Polynomial Representation using Generalized Linked List**

The typical node structure will be:

- Here Flag = 0 means
*variable*is present - Flag = 1 means
*down pointer*is present - Flag = 2 means
*coefficient*and*exponent*is present

*Example:*

9x^{5} + 7xy^{4} + 10xz

In the above example the head node is of variable x. The temp node shows the first field as 2 means coefficient and exponent are present.

Since temp node is attached to head node and head node is having variable x, temp node having coefficient = 9 and exponent = 5. The above two nodes can be read as 9x^{5}.

Similarly, in the above figure, the node temp1 can be read as x^{4}.

- The flag field is 1 means down pointer is there
- temp2 = y
- temp3 = coefficient = 7
- exponent = 1
- flag = 2 means the node contains coefficient and exponent values.
- temp2 is attached to temp3 this means 7y
_{1}and temp2 is also attached to temp1 means - temp1 x temp2
- x
^{4}x 7y^{1}= 7x^{4}y^{1}value is represented by above figure

## Recommended Posts:

- Find the middle of a given linked list in C and Java
- Program for n'th node from the end of a Linked List
- Write a function to get Nth node in a Linked List
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Detect loop in a linked list
- Write a function to delete a Linked List
- Write a function that counts the number of times a given int occurs in a Linked List
- Reverse a linked list
- Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
- Write a function to get the intersection point of two Linked Lists
- Function to check if a singly linked list is palindrome
- The Great Tree-List Recursion Problem.
- Clone a linked list with next and random pointer | Set 1
- Memory efficient doubly linked list
- Given a linked list which is sorted, how will you insert in sorted way

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.