AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 132 of 840

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

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 351 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 235 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 2K+ 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 4K+ 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 229 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 292 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 265 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 671 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

Python Program to Search for an Element in the Linked List without using Recursion

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 579 Views

Searching for an element in a linked list is a fundamental operation. This article demonstrates how to implement a non-recursive search algorithm that finds an element and returns its index position in a linked list. Node Class Definition 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 Linked List Implementation The linked list class contains methods ...

Read More

Python Program to Create a Linked List & Display the Elements in the List

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

A linked list is a linear data structure where elements are stored in nodes, and each node contains data and a reference to the next node. Unlike arrays, linked list elements are not stored in contiguous memory locations. Below is a demonstration of creating a linked list and displaying its elements ? Node Class Structure First, we create a Node class to represent individual elements ? class Node: def __init__(self, data): self.data = data self.next ...

Read More
Showing 1311–1320 of 8,392 articles
« Prev 1 130 131 132 133 134 840 Next »
Advertisements