sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 44 of 98

Binary tree to string with brackets in C++

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

In this problem, we are given a binary tree. Our task is to create a program that will convert a binary tree to string with brackets in C++.The values of the binary tree are integers and it will be fed to the program in a preorder traversing way. The string should contain only integers and parentheses (), also it should be optimized i.e. all the empty pairs should be eliminated.Binary Tree is a tree that has a special condition that each node can have a maximum of two children.Example of a binary tree −Preorder traversal : [4, 1, 8, 3, ...

Read More

C program for pipe in Linux

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 3K+ Views

Here, we will create a C program for pipe in Linux. In this program, we will read some text from the input stream and then print it to the output screen.First, let’s learn basics about pipe in LinuxPipe is used to transfer data, it can be used for communication between process/ command/ program for transferring standard output between two in Linux or Unix based system.One important thing to be noted is that pipes are unidirectional i.e. data can either flow from left to right or from right to left in the program.Here, we will create a pipe that will read ...

Read More

C program to print employee details using Structure

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

Here, we are given a structure containing details of employees. Our task is to create a C program to program to print employee details using structure.The details of the employee that are in the structure are name, age, phone number, salary, and our program will print these details.The details of the employees are pre-declared in the program and we will one by one print all the values. For this, we will create a function that will access the object of the structure and then print all the members of the structure using this object.C Program to print employee details using ...

Read More

Write a function to delete a Linked List in C++ Programming

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

Here, we will create a function that will delete all elements of a linked list one by one.In c/c++, there is no specific function to perform this task but in java, the automatic garbage collection is done to ease deleting linked list.Now, let’s see the implementation of this program, Example#include using namespace std; class Node{    public:    int data;    Node* next; }; void deleteLinkedList(Node** head_ref){    Node* current = *head_ref;    Node* next;    while (current != NULL){       coutnext = (*head_ref);    (*head_ref) = new_node; } int main(){    Node* head = NULL;   ...

Read More

Write a function that generates one of 3 numbers according to given probabilities in C++

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

In this problem, we have to create a function that will generate three numbers based on the given probability.For this, we will use the built-in random number generator function which is rand(a, b) which generates random numbers within the range [a, b] with equal probability.Our task is to return only three numbers A, B, C which have the probability of occurrence as P(A), P(B), P(C) respectively and according to definition of probability P(A) + P(B) + P(C) = 1.To create our function using rand(a, b). we will use its feature that the probability of occurrence of any number from a ...

Read More

Write a function that counts the number of times a given int occurs in a Linked List in C++

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

In this problem, we are given a linked list. Our task is to create a function that will be able to count the number of times a given number occurs in the linked list.Let’s take an example to understand the problem, InputLinked list = 10-> 50 -> 10 -> 20 -> 100 -> 10, int = 10Output3Explaination − the number 10 occurs 3 times in the linked list.The solution to this problem is simple, just traverse the linked list and increment a counter the current node value is equal to the given number.The looping over the nodes of the linked ...

Read More

Write a C program that won't compile in C++

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

Here, we will write some c programs that won’t compile in c++. Though c++ is considered as a successor of c that has all its features and has compatibility with c code there are some programs that won’t compiler or given a compilation error when compiled with c++ compiler.A list of some of the C programs that won’t compile in c++ are −Call to a function before declaration − In c++, function call before declaration gives compilation error. But this works fine in c.Example#include int main(){    printHello();    return 0; } void printHello(){    printf("TutorialsPoint"); }OutputTutorialsPointUsing typecasted pointers ...

Read More

Bitmasking and Dynamic Programming in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 3K+ Views

First, we will learn about bitmasking and dynamic programming then we will solve a problem related to it that will solve your queries related to the implementation.Bitmask also known as mask is a sequence of N -bits that encode the subset of our collection. The element of the mask can be either set or not set (i.e. 0 or 1). This denotes the availability of the chosen element in the bitmask. For example, an element i is available in the subset if the ith bit of mask is set. For the N element set, there can be a 2N mask ...

Read More

Bitonic Sort in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

The bitonic sort is a parallel sorting algorithm that is created for best implementation and has optimum usage with hardware and parallel processor array.It is not the most effective one though as compared to the merge sort. But it is good for parallel implementation. This is due to the predefined comparison sequence which makes comparisons independent of data that are to be sorted.For bitonic sort to work effectively the number of elements should be in a specific type of quantity i.e. the order 2^n.One major part of the bitonic sort is the bitonic sequence which is a sequence whose elements ...

Read More

Bitwise and (or &) of a range in C++

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

In this problem, we are given two integer values a and b. And our task is to find the bitwise and (&) of range from a to b. This means we will have to find the value of a & a+1 & a+2 & … b-1 & b.Let’s take an example to understand the problem, Input − a = 3 , b = 8Output − 0Explanation − 3 & 4 & 5 & 6 & 7 & 8 = 0To solve the problem, a simple solution is starting from a and find bitwise and of all numbers by increasing one ...

Read More
Showing 431–440 of 975 articles
« Prev 1 42 43 44 45 46 98 Next »
Advertisements