Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Program to Reverse only First N Elements of a Linked List

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 357 Views

When it is required to reverse a specific set of elements in a linked list, a method named 'reverse_list' is defined. This iterates through the list and reverses the first N elements while keeping the remaining elements unchanged. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def __init__(self): self.head ...

Read More

Python Program to Find Number of Occurrences of All Elements in a Linked List

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 392 Views

When working with linked lists, it's often useful to find the number of occurrences of elements. This implementation demonstrates how to create a linked list and count occurrences of specific elements using a custom count_elem method. Below is a demonstration for the same − Linked List Implementation First, we create the basic structure with Node and LinkedList classes: class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: ...

Read More

Python Program to Find the first Common Element between the 2 given Linked Lists

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 406 Views

When it is required to find the common element that occurs for the first time between two linked lists, a method to add elements to the linked list, and a method to get the common element that occurs for the first time in these linked lists is defined. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList_structure: def ...

Read More

Python Program to Add Corresponding Positioned Elements of 2 Linked Lists

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 276 Views

When working with linked lists, you may need to add corresponding elements from two lists at the same positions. This involves traversing both lists simultaneously and creating a new linked list with the sum of elements at each position. Below is a demonstration for the same − Node and LinkedList Classes First, we define the basic structure for nodes and linked lists ? class Node: def __init__(self, data): self.data = data self.next = None ...

Read More

Python Program to Implement Queue Data Structure using Linked List

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

A queue is a linear data structure that follows the First In First Out (FIFO) principle. When implementing a queue using a linked list, we need methods to add elements at the rear (enqueue) and remove elements from the front (dequeue). Queue Implementation Structure Our queue implementation consists of two classes ? class Node: def __init__(self, data): self.data = data self.next = None class Queue: def __init__(self): ...

Read More

Python Program to Implement a Stack using Linked List

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 5K+ Views

When implementing a stack data structure using a linked list, we need methods to add (push) elements to the top and remove (pop) elements from the top. In a stack, the last element added is the first one to be removed (LIFO - Last In First Out). Node Class First, we create a Node class to represent individual elements in the linked list ? class Node: def __init__(self, data): self.data = data self.next = None ...

Read More

Python Program to Print the Alternate Nodes in a Linked List using Recursion

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 314 Views

When working with linked lists, we often need to print alternate nodes (1st, 3rd, 5th, etc.). This can be achieved using recursion by skipping one node at each recursive call. We'll create a linked list class with methods to add elements and a recursive function to print alternate nodes. Node Class First, let's define a simple Node class to represent individual elements in our linked list ? class Node: def __init__(self, data): self.data = data self.next ...

Read More

Python Program to Find the Length of the Linked List without using Recursion

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 483 Views

When it is required to find the length of a linked list without using recursion, we define methods to add elements to the linked list and calculate its length using iterative approach. This approach uses a simple loop to traverse through all nodes and count them. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): ...

Read More

Python Program to Display the Nodes of a Linked List in Reverse without using Recursion

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 372 Views

When it is required to display the nodes of a linked list in reverse without using the method of recursion, we can use an iterative approach. This involves finding the last unprinted node in each iteration and displaying it. Below is a demonstration for the same − Example class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): ...

Read More

Python Program to Display all the Nodes in a Linked List using Recursion

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 787 Views

When it is required to display the elements/nodes in a linked list using recursion, we need a method to add values to the linked list and a recursive helper method that calls itself repeatedly to print the values. The recursive approach provides an elegant way to traverse the entire linked list. Below is a demonstration for the same − Node and LinkedList Classes First, we define the basic structure of our linked list ? class Node: def __init__(self, data): self.data = data ...

Read More
Showing 5021–5030 of 61,299 articles
« Prev 1 501 502 503 504 505 6130 Next »
Advertisements