Found 26504 Articles for Server Side Programming

Delete Leaves With a Given Value in C++

Arnab Chakraborty
Updated on 29-Apr-2020 10:24:59

153 Views

Suppose we have a binary tree and an integer target, we have to delete all the leaf nodes with value target. We have to keep in mind that once we delete a leaf node with a value target if it's parent node becomes a leaf node and has the value target, it should also be deleted (we need to continue doing that until we can't). So if the tree is like below, and the target is 2, then the final tree will be like the last one −To solve this, we will follow these steps −Define a recursive method called ... Read More

Print Words Vertically in Python

Arnab Chakraborty
Updated on 29-Apr-2020 09:50:19

4K+ Views

Suppose we have a string s. We have to find all the words vertically in the same order in which they appear in s. Here words are returned as a list of strings, we have to complete with spaces when is necessary. (Trailing spaces are not allowed). Each word would be put on only one column and that in one column there will be only one word. So if the input string is “HOW ARE YOU”, then the output will be [“HAY”, “ORO”, “WEU”]To solve this, we will follow these steps −s := make a list of strings split by ... Read More

Delete elements in C++ STL list

Ayush Gupta
Updated on 23-Mar-2020 08:48:31

232 Views

IIn this tutorial, we will be discussing a program to understand how to delete elements in the C++ STL list.For this, we will be using the pop_back() and pop_front() function to delete the element from last and the front respectively.Example Live Demo#include #include using namespace std; int main(){    listlist1={10,15,20,25,30,35};    cout

Initialization of a multidimensional arrays in C/C++ Program

Ayush Gupta
Updated on 23-Mar-2020 08:39:05

195 Views

In this tutorial, we will be discussing a program to understand how to initiate a multidimensional array in C/C++.While declaring a multidimensional array, the value of the leftmost dimension can be left empty, but all other dimensions must be provided.Example Live Demo#include int main(){    int a[][2] = {{1,2},{3,4}};    printf("%lu", sizeof(a));    getchar();    return 0; }Output16

Extended Integral Types (Choosing the correct integer size in C/C++)

Ayush Gupta
Updated on 23-Mar-2020 08:37:36

124 Views

In this tutorial, we will be discussing a program to understand extended integral types in C/C++.The data types in C are very loosely defined. Their range values changes on the basis of the compiler being 32 or 64 bit. To specify the compiler range you want to use in your program we use intN_t.Example Live Demo#include using namespace std; int main(){    uint8_t i; //mentioning the bit to be 8    i = 0;    cout

File Handling through C++ Classes

Ayush Gupta
Updated on 11-Dec-2024 19:20:31

1K+ Views

In this tutorial, we will be discussing a program to understand File Handling through C++ classes. What's File Handling? File handling is an important concept in programming, which allows a program to read from and write to files. C++ has built-in classes and functions for file handling, which is done using file stream classes that are part of the  library. The most common file stream classes in C++ are ofstream, ifstream, fstream. ofstream: This class is used for output file streams, where it allows the user to write data to files. ... Read More

Draw a line in C++ graphics

Ayush Gupta
Updated on 23-Mar-2020 08:30:09

6K+ Views

In this tutorial, we will be discussing a program to draw a line in C++ graphics.To implement different shapes and sizes, animations, graphics.h library is used in C++.Example#include int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, "");    line(150, 150, 450, 150);    line(150, 200, 450, 200);    line(150, 250, 450, 250);    getch();    closegraph();    return 0; }Output

Does C++ compiler create default constructor when we write our own?

Ayush Gupta
Updated on 23-Mar-2020 08:27:02

203 Views

In this tutorial, we will be discussing a program to understand if the C++ compiler creates a default constructor when we write our own.Generally, the C++ compiler uses the default constructor when no one is defined, but always uses the one defined by the user if any.Example Live Demo#include using namespace std; class myInteger{ private:    int value;    //other functions in class }; int main(){    myInteger I1;    getchar();    return 0; }OutputCompiles successfullyExample#include using namespace std; class myInteger{    private:       int value;    public:       myInteger(int v) //user-defined constructor    { value = ... Read More

Delete and free() in C++ Program

Ayush Gupta
Updated on 23-Mar-2020 08:24:21

155 Views

In this tutorial, we will be discussing a program to understand delete() and free() functions in C++.Both of these functions are primarily used for the same purpose i.e freeing up unused memory. The delete() operator is for the ones allocated using new() and free() for the ones allocated using malloc().Example#include #include int main(){    int x;    int *ptr1 = &x;    int *ptr2 = (int *)malloc(sizeof(int));    int *ptr3 = new int;    int *ptr4 = NULL;    //incorrect usage of delete    delete ptr1;    delete ptr2;    //correct usage of delete    delete ptr3;    delete ptr4;    getchar();    return 0; }

Different methods to reverse a string in C/C++

Ayush Gupta
Updated on 23-Mar-2020 08:22:23

3K+ Views

In this tutorial, we will be discussing a program to understand different methods to reverse a string in C/C++.ExampleUser-defined reverse() function − Live Demo#include using namespace std; //function to reverse given string void reverse_str(string& str){    int n = str.length();    for (int i = 0; i < n / 2; i++)       swap(str[i], str[n - i - 1]); } int main(){    string str = "tutorialspoint";    reverse_str(str);    cout

Advertisements