Found 26504 Articles for Server Side Programming

Python Program to Find the Largest Element in a Doubly Linked List

AmitDiwan
Updated on 14-Apr-2021 13:49:57

249 Views

When it is required to find the largest element in a doubly linked list, a method to add elements to the doubly linked list, a method to print the elements of the doubly linked list, and a method to find the largest element in a doubly 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       self.prev = None class DoublyLinkedList_structure:    def __init__(self):       self.first = None       self.last = None ... Read More

Python Program to Detect the Cycle in a Linked List

AmitDiwan
Updated on 14-Apr-2021 13:46:26

453 Views

When it is required to detect a cycle in a linked list, a method to add elements to the linked list, and a method to get the element in the linked list are defined. Another method is defined that checks if the head and rear values are same or not. Based on this result, cycles are detected.Below is a demonstration for the same −Exampleclass Node:    def __init__(self, data):       self.data = data       self.next = None class LinkedList_structure:    def __init__(self):       self.head = None       self.last_node = None ... Read More

Python Program to Check whether 2 Linked Lists are Same

AmitDiwan
Updated on 14-Apr-2021 13:38:45

301 Views

When it is required to check if two linked lists are same, a method to add elements to the linked list, and a method to check the equality of the elements in the linked lists are defined.Below is a demonstration for the same −Exampleclass Node:    def __init__(self, data):       self.data = data       self.next = None class LinkedList_structure:    def __init__(self):       self.head = None       self.last_node = None    def add_vals(self, data):       if self.last_node is None:          self.head = Node(data)     ... Read More

Python Program to Implement Binary Tree using Linked List

AmitDiwan
Updated on 14-Apr-2021 13:31:38

589 Views

When it is required to implement a binary tree data structure using a linked list, a method to set the root node, a method to perform in-order traversal, to insert element to the left of the root node, a method to insert element to the right of the root node, and a method to search the values are defined.Below is a demonstration for the same −Example Live Democlass BinaryTree_structure:    def __init__(self, key=None):       self.key = key       self.left = None       self.right = None    def set_root(self, key):       self.key = ... Read More

Python Program to Implement Queue Data Structure using Linked List

AmitDiwan
Updated on 14-Apr-2021 13:26:46

2K+ Views

When it is required to implement a queue data structure using a linked list, a method to add (enqueue operation) elements to the linked list, and a method to delete (dequeue operation) the elements of the 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 Queue_structure:    def __init__(self):       self.head = None       self.last = None    def enqueue_operation(self, data):       if self.last is None:          self.head = Node(data)     ... Read More

Python Program to Implement a Stack using Linked List

AmitDiwan
Updated on 14-Apr-2021 13:22:00

4K+ Views

When it is required to implement a stack data structure using a linked list, a method to add (push values) elements to the linked list, and a method to delete (pop values) the elements of the 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 Stack_structure:    def __init__(self):       self.head = None    def push_val(self, data):       if self.head is None:          self.head = Node(data)       else: ... Read More

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

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

335 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

157 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

200 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

447 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

Advertisements