Found 33676 Articles for Programming

Deletions of “01” or “10” in binary string to make it free from “01” or “10" in C++?

AmitDiwan
Updated on 16-Jan-2021 07:40:45

113 Views

Let us first declare our initial string and calculate its length and pass them to the deleteSubstr(str,length) function.string str = "01010110011"; int length = str.length(); cout

Deleting a binary tree using the delete keyword in C++?

AmitDiwan
Updated on 16-Jan-2021 07:32:09

192 Views

Let us first define our binary tree using a class containing int data, btree_node * rightChild, btree_node * leftChild. The leftChild and rightChild are pointers to btree_node. All the members in our class are public.class btree_node {    public:       int data;       btree_node* leftChild;       btree_node* rightChild;For creating a new node we have the constructor function that takes the int value as parameter to assign it to the newly created node value. The leftChild and rightChild are set to null.btree_node(int data){    this->data = data;    this->leftChild = NULL;    this-> = NULL; ... Read More

Delete N nodes after M nodes of a linked list in C++?

AmitDiwan
Updated on 16-Jan-2021 07:26:34

232 Views

Let us first define our linked list that contains data and the pointer to the next node.struct Node {    int data;    struct Node* next; };We then create our createList(Node ** headPtr, int new_data) function which takes a doublePointer to the Node and an int value. Inside the function we assign the newly created node next pointer to the headptr and then the headptr to the newly created node.void createList(Node ** headPtr, int new_data){    Node* newNode = new Node();    newNode->data = new_data;    newNode->next = (*headPtr);    (*headPtr) = newNode; }The deleteNnodesAfterM(Node *head, int M, int N) ... Read More

Delete middle of linked list in C++?

AmitDiwan
Updated on 16-Jan-2021 07:19:23

407 Views

Let us first define our linked list that contains data and the pointer to the next node.struct Node {    int data;    struct Node* next; };Next we create our createNode(int data) function that takes int data as parameter and returns the newly created node after assigning the parameter value. The next pointer to the node will be null.Node* createNode(int data){    struct Node* newNode = new Node;    newNode->data = data;    newNode->next = NULL;    return newNode; }Now we have our deleteMiddle(struct Node* head) function which takes the root node. If the root node isn’t null then it ... Read More

Delete leaf nodes with value k in C++?

AmitDiwan
Updated on 16-Jan-2021 07:13:20

142 Views

Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node {    int data;    struct Node *leftChild, *rightChild; };Next we create our newNode(int data) function that takes an int value and assign it to the data member of the node. The function returns the pointer to the created struct Node. Also, the left and right child of the newly created node are set to null.struct Node* newNode(int ... Read More

Delete leaf nodes with value as x in C++?

AmitDiwan
Updated on 16-Jan-2021 07:05:24

207 Views

Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node {    int data;    struct Node *leftChild, *rightChild; };Next we create our newNode(int data) function that takes an int value and assign it to the data member of the node. The function returns the pointer to the created struct Node. Also the left and right child of the newly created node are set to null.struct Node* newNode(int ... Read More

Delete array element in given index range [L – R] in C++?

AmitDiwan
Updated on 16-Jan-2021 06:58:22

568 Views

Let us first define the original array and the exclusive range for deletion of the array elements and also find the original array length −int arr[] = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; int L = 2, R = 6; int length = sizeof(arr) / sizeof(arr[0]);Now we loop in the array and if index position (i) is greater than L or R we increment the variable k which will be used to shift positions(delete) of array element once the index value (i) lies between the range L and R. Also, the new length of the ... Read More

Delete an element from array using two traversals and one traversal in C++?

AmitDiwan
Updated on 16-Jan-2021 06:48:41

109 Views

Two Traversals Let us first define the original array and the element to be searched and deleted from the array −int ele = 5; int arr = [1,2,3,4];Now we loop in the array to find the given element −for (i=0; i

Check whether two strings are equivalent or not according to given condition in Python

Arnab Chakraborty
Updated on 16-Jan-2021 05:09:48

390 Views

Suppose we have two strings s and t of same size. We have to check whether s and t are equivalent or not. There are few conditions to check:They both are equal. Or, If we divide the s into two contiguous substrings of same size and the substrings are s1 and s2 and also divide t same like, s into t1 and t2, then one of the following should be valid:s1 is recursively equivalent to t1 and s2 is recursively equivalent to t2s1 is recursively equivalent to t2 and s2 is recursively equivalent to t1So, if the input is like ... Read More

Check whether two strings are anagram of each other in Python

Arnab Chakraborty
Updated on 16-Jan-2021 05:08:38

422 Views

Suppose we have two strings s and t we have to check whether they are anagram of each other or not.So, if the input is like s = "bite" t = "biet", then the output will be True as s ad t are made of same characters.To solve this, we will follow these steps −if size of s is not same as size of t, thenreturn Falsesort characters of s and treturn true if s is exactly same as t, otherwise falseLet us see the following implementation to get better understanding −Example CodeLive Demodef solve(s, t):    if len(s) != ... Read More

Advertisements