# Triply Linked list

A Triply Linked List (TLL) is a modified version of the doubly linked list. It has an additional pointer, the top pointer, in each node, along with the next and previous pointers and the data field. This extra pointer can be used for various purposes, such as storing equal values on the same level.

The procedure to insert a new node in a TLL is as follows:

1. Inserting a new node: To upload a node to a linked listing, we should find its correct position primarily based on the order of the nodes. The new node becomes the pinnacle and tail if the list is empty. If the new node is smaller than the pinnacle node, it is introduced at the beginning. If the new node isn't always smaller than the pinnacle node, we traverse the list till we discover the first node greater than the brand-new node. A new node is brought on the quit if one of these nodes doesn't exist. If any such node does exist, the brand-new node is brought earlier than it. If the new node equals an existing node, it's miles are added at the pinnacle.
2. Traverse the List from the Head: Start from the head and continue to the next node. If the top of the current node is not empty, print the top node first and then continue traversing the rest of the list.
3. Traverse the List from the Tail or reverse traversal: Start from the tail and continue to the previous node. If the top of the current node is not empty, print the top node first and then continue traversing the rest of the list.

However, it's important to note that a "triple-linked list" is often called a binary tree, not a list. The third node pointer basically modifications the record's shape's nature. The term "list" implies a sequential structure and adding a 3rd pointer might make it more than just a linear data structure.

Here's a representation of a TLL node:

The Triply Linked List (TLL) is a more complex statistics shape than singly or doubly connected lists because of the addition of a 3rd pointer, bearing in mind greater flexibility and complexity in list operations.

Operations that are executed on a TLL:

• Insertion at the beginning: A new node can be added at the start of the listing by adjusting the next pointer of the brand-new node to factor to the current head of the list, the prev pointer to null, and the pinnacle pointer to the total node of the pinnacle. The head of the list is then updated to the new node.

Java Representation:

Output:

• Insertion at the end: A new node can be brought at the end of the list by way of adjusting the following pointer of the brand-new node to null, the prev pointer to the current tail of the listing, and the pinnacle pointer to the whole node of the tail. The tail of the listing is then updated to the new node.
• Deletion: A node may be deleted from the listing by adjusting the node's next pointer earlier than it to factor to the node after it and the previous pointer after it to factor to the node earlier than it. If the node to be deleted is the pinnacle or tail of the list, the head or tail is up to date as a result.
• Searching: A node can be searched in the list by traversing the list from the head to the tail and checking each node's data field. If a match is found, the node is returned.
• Sorting: The list can be sorted by swapping the data fields of the nodes, not the nodes themselves. This can be done using any sorting algorithm like bubble sort, insertion sort, etc.

Remember, the complexity of those operations can vary. For example, searching for a node in a TLL can take O(n) time within the worst case, wherein n is the wide variety of nodes inside the listing. It's additionally crucial to notice that at the same time as a TLL can be useful in specific situations, it also comes with multiplied complexity and memory utilization because of the additional pointer. Therefore, it's critical to recollect the change-offs earlier than identifying to use a TLL in your application.

Next TopicCOUNT OF ZEROES