Programming Articles - Page 1522 of 3363

Delete all Prime Nodes from a Singly Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:51:52

565 Views

In this tutorial, we are going to learn how to delete all prime nodes from a singly linked list.Let's see the steps to solve the problem.Write struct with data and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Iterate over the singly linked list. Find whether the current node data is prime or not.If the current data is prime, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to next ... Read More

Delete all Prime Nodes from a Doubly Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:49:35

228 Views

In this tutorial, we are going to learn how to delete all prime nodes from a doubly linked list.Let's see the steps to solve the problem.Write struct with data, prev and next pointers.Write a function to insert the node into the doubly linked list.Initialize the doubly linked list with dummy data.Iterate over the doubly linked list. Find whether the current node data is prime or not.If the current data is prime, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to ... Read More

Delete all Non-Prime Nodes from a Singly Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:47:16

199 Views

In this tutorial, we are going to learn how to delete all prime nodes from a singly linked list.Let's see the steps to solve the problem.Write struct with data and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Iterate over the singly linked list. Find whether the current node data is prime or not.If the current data is not prime, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to ... Read More

Delete a node in a Doubly Linked List in C++

Hafeezul Kareem
Updated on 03-Dec-2024 09:41:31

7K+ Views

In this tutorial, we are going to learn how to delete a node in the doubly linked list. Approach Let's see the steps to solve the problem. Write struct with data, prev, and next pointers. Write a function to insert the node into the doubly linked list. Initialize the doubly ... Read More

Delete a Node from linked list without head pointer in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:43:17

2K+ Views

In this tutorial, we are going to learn how to delete a node without head pointer in a singly linked list.Let's see the steps to solve the problem.Write struct with data, and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Take a node from the linked list using the next pointer.Move the delete node to the next node.ExampleLet's see the code. Live Demo#include using namespace std; struct Node {    int data;    struct Node* next; }; void deleteNodeWithoutHead(struct Node* deletingNode) {    if (deletingNode == NULL) {   ... Read More

Delete a Linked List node at a given position in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:42:00

4K+ Views

In this tutorial, we are going to learn how to delete a node in singly linked list with the given position.Let's see the steps to solve the problem.Write struct with data, and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Initialize the position to delete the node.Iterate over the linked list and find the node with the given position to delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to next ... Read More

Delete a Doubly Linked List node at a given position in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:38:44

2K+ Views

In this tutorial, we are going to learn how to delete a node in doubly linked list with the given position.Let's see the steps to solve the problem.Write struct with data, prev and next pointers.Write a function to insert the node into the doubly linked list.Initialize the doubly linked list with dummy data.Initialize the position to delete the node.Iterate over the linked list and find the node with the given position to delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to ... Read More

Deepest left leaf node in a binary tree in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:36:43

320 Views

In this tutorial, we are going to find the deepest left leaf node in the binary tree. Let's see the binary tree.   A       B    C D       E       F                      GLet's see the steps to solve the problem.Write a Node struct with char, left, and right pointers.Initialize the binary tree with dummy data.Write a recursive function to find the deepest left node in the binary function. It takes three argument root node, isLeftNode, and result pointer to store the deepest node.If the ... Read More

Check if all occurrences of a character appear together in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:48:54

370 Views

Suppose we have a string s and another character c, we have to check whether all occurrences of c appear together in s or not. If the character c is not present in s then also return true.So, if the input is like s = "bbbbaaaaaaaccddd", c = 'a', then the output will be True.To solve this, we will follow these steps −flag := Falseindex := 0n := size of stringwhile index < n, doif string[index] is same as c, thenif flag is True, thenreturn Falsewhile index < n and string[index] is same as c, doindex := index + 1flag ... Read More

Check if all enemies are killed with bombs placed in a matrix in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:46:49

204 Views

Suppose we have a matrix mat. There are few different values as follows The cells of matrix can hold any of these 3 characters0 for empty area.1 for bomb.2 for Enemies.Now bomb can blast in only horizontal and vertical directions from one end to another. We have to check whether all enemies will die when bomb explodes or not.So, if the input is like0020010002000010then the output will be True, because bomb at place [1, 1] can fill enemy at place [2, 1] and enemy at [0, 2] will be killed by bomb placed at [3, 2].To solve this, we will ... Read More

Advertisements