Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 412 of 2109
Python program to insert a new node at the end of the Circular Linked List
When it is required to insert a new node at the end of the circular linked list, a Node class needs to be created. In this class, there are two attributes: the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the tail are adjacent to each other. They are connected to form a circle, and don't have NULL value in the last node. Instead, the last node points back to the first node. ...
Read MorePython program to insert a new node at the beginning of the Circular Linked List
When it is required to insert a new node at the beginning of a circular linked list, a 'Node' class needs to be created. In this class, there are two attributes, the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have 'NULL' value in the last node. Instead, the last node points back to the first node. Node Class Structure First, we create ...
Read MorePython program to find the maximum and minimum value node from a circular linked list
When it is required to find the maximum and minimum node values from a circular linked list, a Node class needs to be created. In this class, there are two attributes: the data present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the tail are adjacent to each other. They are connected to form a circle, and don't have None value in the last node − instead, the last node points back to the first node. Implementation The implementation involves creating a Node ...
Read MorePython program to delete a node from the middle of the Circular Linked List
When it is required to delete a node from the middle of the circular linked list, a Node class needs to be created. In this class, there are two attributes: the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the rear are adjacent to each other. They are connected to form a circle, and don't have NULL value in the last node. Another class needs to be created that would have an initialization function, and the head of the node ...
Read MorePython program to delete a node from the end of the Circular Linked List
When it is required to delete a node from the end of a circular linked list, a Node class needs to be created. In this class, there are two attributes: the data that is present in the node, and the access to the next node of the linked list. In a circular linked list, the head and the tail are adjacent to each other. They are connected to form a circle, and don't have NULL value in the last node − instead, the last node points back to the first node. Node Class Structure The Node class ...
Read MorePython Program to Print an Inverted Star Pattern
In this article, we'll learn how to print inverted star patterns in Python. An inverted star pattern displays stars in descending order, where each row has fewer stars than the previous one. For example, with N=5 rows ? ***** **** *** ** * Basic Inverted Star Pattern The most common approach uses nested for loops − the outer loop controls rows, and the inner loop prints stars for each row. Using Nested Loops Here's how to create an inverted star pattern with spaces between stars ? # Number of rows N ...
Read MorePython program to create and display a Circular Linked List
A circular linked list is a data structure where the last node points back to the first node, forming a circle. Unlike regular linked lists that end with None, circular linked lists have no end − the traversal can continue indefinitely. To implement a circular linked list in Python, we need two classes: a Node class to represent individual elements, and a CircularLinkedList class to manage the list operations. Node Class Structure Each node contains data and a reference to the next node ? class Node: def __init__(self, data): ...
Read MorePython program to create a Circular Linked List of n nodes and display it in reverse order
When it is required to create a circular linked list and display it in the reverse order, a Node class needs to be created. However, the example below demonstrates a regular linked list implementation, not a true circular linked list. In a circular linked list, the last node points back to the first node instead of pointing to None, forming a circle. The head and tail are connected to each other. To display the data elements in reverse order, we can either reverse the list structure or traverse it backwards. Regular Linked List (Current Implementation) The current ...
Read MorePython Program to Shuffle Deck of Cards
When it is required to shuffle a deck of cards using Python, the itertools and the random packages need to be used. Random library has a method named shuffle() that can be used to mix up and randomize the data. Creating and Shuffling a Deck Below is a demonstration of how to create a standard deck and shuffle it ? import itertools import random # Create a deck of cards using itertools.product deck = list(itertools.product(range(1, 14), ['Spade', 'Heart', 'Diamond', 'Club'])) print("Original deck created with", len(deck), "cards") print("The cards are being shuffled...") # Shuffle ...
Read MoreSort list of tuples by specific ordering in Python
When you need to sort a list of tuples by a specific element or custom ordering, Python's sorted() function with a key parameter provides a flexible solution. The key parameter accepts a function that determines the sorting criteria. A list of tuples is a common data structure where each tuple contains related elements. Sorting such lists by specific tuple elements is frequently needed in data processing tasks. Sorting by Second Element Use a lambda function to specify which tuple element to sort by ‒ def tuple_sort(my_tup): return sorted(my_tup, key=lambda x: x[1]) ...
Read More