C++ Articles

Page 245 of 597

Convert singly linked list into circular linked list in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 649 Views

In this tutorial, we will be discussing a program to convert a singly linked list into circular linked list.For this we will be provided with a singly linked list. Our task is to take the elements of that list and get it converted into a circular linked list.Example#include //node structure of linked list struct Node {    int data;    struct Node* next; }; //converting singly linked list //to circular linked list struct Node* circular(struct Node* head){    struct Node* start = head;    while (head->next != NULL)       head = head->next;    //assigning start to the ...

Read More

Convert singly linked list into XOR linked list in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 361 Views

In this tutorial, we will be discussing a program to convert a singly linked list into XOR linked list.For this we will be provided with a singly linked list. Our task is to take the elements of that list and get it converted into a XOR linked list.Example#include using namespace std; //node structure of linked list struct Node {    int data;    struct Node* next; }; //creation of new node Node* newNode(int data){    Node* temp = new Node;    temp->data = data;    temp->next = NULL;    return temp; } //printing singly linked list void print(Node* head){ ...

Read More

Convert String into Binary Sequence in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we will be discussing a program to convert string into Binary sequence.For this we will be provided with a string of characters. Our task is to convert each of the character into its binary equivalent and print it out spaced between for different characters.Example#include using namespace std; //converting into binary equivalent void convert_binary(string s){    int n = s.length();    for (int i = 0; i 0){          (val % 2)? bin.push_back('1') :          bin.push_back('0');          val /= 2;       }       reverse(bin.begin(), bin.end());       cout

Read More

Convert Ternary Expression to a Binary Tree in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 311 Views

In this tutorial, we will be discussing a program to convert ternary expression to a binary tree.For this we will be provided with a ternary expression. Our task is to convert the given expression in the form of a binary tree depending upon the various paths(choices) possible.Example#include using namespace std; //node structure of tree struct Node {    char data;    Node *left, *right; }; //creation of new node Node *newNode(char Data){    Node *new_node = new Node;    new_node->data = Data;    new_node->left = new_node->right = NULL;    return new_node; } //converting ternary expression into binary tree Node *convertExpression(string ...

Read More

Convert the array such that the GCD of the array becomes 1 in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 312 Views

In this tutorial, we will be discussing a program to convert the array such that the GCD of the array becomes one.For this we will be provided with an array and a positive integer k. Our task is to convert the array elements such that the GCD of elements is 1 while only dividing the array elements by k any number of times until the element is less than k.Example#include using namespace std; //calculating the GCD of array int calculate_gcd(int* arr, int n){    int gcd = arr[0];    for (int i = 1; i < n; i++)   ...

Read More

Convert the ASCII value sentence to its equivalent string in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 912 Views

In this tutorial, we will be discussing a program to convert the ASCII value sentence to its equivalent string.For this we will be provided with a string containing the ASCII codes. Our task is to convert the given string into the equivalent characters and print it back.Example#include using namespace std; //converting the ASCII sequence into //character string void convert_ASCII(string str, int len){    int num = 0;    for (int i = 0; i < len; i++) {       //appending the current digit       num = num * 10 + (str[i] - '0');       //checking if number is within range       if (num >= 32 && num

Read More

Convert the string into palindrome string by changing only one character in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 465 Views

In this tutorial, we will be discussing a program to convert the string into palindrome string by changing only one character.For this we will be provided with a string. Our task is to convert the given string into a palindrome by changing only one character.Example#include using namespace std; //checking if conversion to palindrome //is possible bool if_palindrome(string str){    int n = str.length();    //counting number of characters    //to be changed    int count = 0;    for (int i = 0; i < n/2; ++i)       if (str[i] != str[n - i - 1])          ++count;    return (count

Read More

Convert the undirected graph into directed graph such that there is no path of length greater than 1 in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 260 Views

In this tutorial, we will be discussing a program to convert the undirected graph into a directed graph such that there is no path of length greater than 1.For this we will be provided with an undirected graph. Our task is to convert that graph into a direct one given no path has a length greater than 1.Example#include using namespace std; #define N 100005 //storing the graph vector gr[N]; //storing colour of each vertex int colour[N]; vector edges; bool bip; //adding edges to the graph void add_edge(int x, int y){    gr[x].push_back(y);    gr[y].push_back(x);    edges.push_back(make_pair(x, y)); } //checking ...

Read More

Print all pairs of anagrams in a given array of strings in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 529 Views

In this problem, we are given an array of strings and we have to print all pairs of anagrams of that given array.Anagrams are strings that are formed by rearranging the character of another string. Like − hello and lolheLet’s take an example to understand the problem −Input: array = {“hello”, “hrdef”, “from”, “lohel”, “morf”}. Output: [hello, lohel] , [from , morf]To solve this problem, we will use the nesting of loops. We need two nested loops, the outer loop will traverse over the array and select elements. The nested loop will check each of the string and check if ...

Read More

Print all pairs in an unsorted array with equal sum in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 386 Views

In this problem, we have an unsorted array and we have to print all pairs within this array that have an equal sum.Let’s take an example to understand the problem −Input: array = [12, 13, 20, 5] Output: [12, 13] and [20, 5] have sum 25.To solve this problem, we will have to find pairs of the same sum. For this, we will check pairs for the same sum. And to avoid duplicate pairs, we will use the map.For this, we will need two maps, one to store all sum pairs and their sum and others to store all sum ...

Read More
Showing 2441–2450 of 5,962 articles
« Prev 1 243 244 245 246 247 597 Next »
Advertisements