Found 10476 Articles for Python

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

AmitDiwan
Updated on 14-Apr-2021 13:18:54

337 Views

When it is required to print the alternate nodes in a linked list without using recursion, a method to add elements to the linked list, a method to display the elements of the linked list, and a method to get the alternate values of a linked list are defined.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None    def add_value(self, my_data):       ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 13:16:13

160 Views

When it is required to print the alternate nodes in a linked list using recursion, a method to add elements to the linked list, a method to display the elements of the linked list, and a method to get the alternate values of a linked list are defined. Another helper function is used that calls the previously defined method to get alternate values.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None ... Read More

Python Program to Count the Number of Occurrences of an Element in the Linked List without using Recursion

AmitDiwan
Updated on 14-Apr-2021 13:13:17

206 Views

When it is required to count the number of occurrences of a specific element in a linked list without using recursion, a method to add elements to the linked list, a method to display the elements of the linked list, and a method to count the occurrences of a value are defined.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None    def add_value(self, my_data): ... Read More

Python Program to Count the Number of Occurrences of an Element in the Linked List using Recursion

AmitDiwan
Updated on 14-Apr-2021 13:11:12

449 Views

When it is required to count the number of occurrence of a specific element of a linked list with the help of recursion, a method to add elements to the linked list, a method to print the elements of the linked list, and a method to count the occurrence of an element in the linked list is defined. A helper function is defined, since recursion is being used. This helper function calls the previously defined occurrence counting function.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 13:07:54

190 Views

When it is required to find the length of a linked list without using recursion, a method to add elements to the linked list, and a method to calculate the length of the linked list is defined.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None    def add_value(self, my_data):       if self.last_node is None:          self.head = Node(my_data)   ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 13:05:11

218 Views

When it is required to find the length of a linked list with the help of recursion, a method to add elements to the linked list, and a method to calculate the length of the linked list is defined. A helper function is defined that is called with the help of the previously defined length calculation method.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 13:02:14

214 Views

When it is required to display the nodes of a linked list in reverse without using the method of recursion, a method to add elements to the linked list, and a method to display the elements in reverse order is defined.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None    def add_value(self, my_data):       if self.last_node is None:         ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 12:59:35

592 Views

When it is required to display the elements/nodes in a linked list, using recursion method, a method to add values to the linked list, and a method to print the elements of a Linked List. It would also have a helper method that uses recursion, i.e calls the helper function again and again to print the values.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 12:57:08

172 Views

When it is required to display the elements/nodes in a linked list in reverse order, using recursion method, a method to add values to the linked list, as well as a method to reverse the elements of a Linked List. It would also have a helper method that uses recursion, i.e calls the helper function again and again to compute values.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None     ... Read More

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

AmitDiwan
Updated on 14-Apr-2021 12:53:42

526 Views

When it is required to search for an element in a linked list without using recursion method, a method to add values to the linked list, as well as a method to display the elements of a Linked List.It would also have a method that helps find the index of the element that is being searched.Below is a demonstration for the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class my_linked_list:    def __init__(self):       self.head = None       self.last_node = None ... Read More

Advertisements