Programming Articles - Page 2736 of 3366

C++ Program to Perform Dictionary Operations in a Binary Search Tree

Farhan Muhamed
Updated on 15-May-2025 19:35:26

2K+ Views

A dictionary is a collection of key-value pairs where, keys are unique and used to identify corresponding values in the dictionary. In this article, we will learn how to perform dictionary operations such as insertion, search, and traversal using a binary search tree (BST) in C++. What is BST? A binary search tree (BST) is a tree data structure, where each node has at most two children and follows two rules: the left subtree contains keys less than the node’s key, and the right subtree contains keys greater than the node’s key. This structure is same as how a ... Read More

C++ Program to Implement Ternary Tree

Farhan Muhamed
Updated on 23-May-2025 11:18:01

694 Views

A ternary tree is a type of tree data structure in which each node can have at most three children. In this article, we will learn how to implement a ternary tree in C++ using basic class structures and pointers. What is Ternary Tree? A ternary tree is a tree in which each node has up to three children, that is left, middle, and right. It is same as a binary tree, but with an extra child node for each node. Each node in a ternary tree stores a data value and pointers to its three child nodes. ... Read More

How to insert a record into a table in a database using JDBC API?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

A. You can insert records in to a table using the INSERT query.SyntaxINSERT INTO TABLE_NAME (column1, column2, column3, ...columnN) VALUES (value1, value2, value3, ...valueN); Or, INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ...valueN);To insert a record into a table in a database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using ... Read More

What is the easiest way to convert int to string in C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

443 Views

In this section, we will see how to convert an integer to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42 Output: This program will return the string equivalent result of that number like “42”AlgorithmStep 1: Take a number from the user Step 2: Create an ... Read More

Tokenizing a string in C++

Farhan Muhamed
Updated on 13-Jun-2025 18:51:05

7K+ Views

Tokenization refer to the process of breaking a string based on certain delimiters such as spaces, commas, semicolons, or any other character. Mostly white spaces are used as delimiters to tokenize strings. In this article, we will discuss all the ways tokenize a string in C++. For example, if we have a string like "Hello, World! Welcome to Tutorialspoint.", we can tokenize it like this: string str = "Hello, World! Welcome to Tutorialspoint."; tokens = {"Hello", "World", "Welcome", "to", "Tutorialspoint"}; Tokenizing a String in C++ In C++, we can tokenize a string using various methods. Here are ... Read More

The most elegant way to iterate the words of a string using C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

164 Views

There is no one elegant way to iterate the words of a C/C++ string. The most readable way could be termed as the most elegant for some while the most performant for others. I've listed 2 methods that you can use to achieve this. First way is using a stringstream to read words separated by spaces. This is a little limited but does the task fairly well if you provide the proper checks. For example, >Example Code Live Demo#include #include #include #include using namespace std; int main() {    string str("Hello from the dark side");   ... Read More

String tokenisation function in C

Smita Kapse
Updated on 30-Jul-2019 22:30:25

6K+ Views

In this section, we will see how to tokenize strings in C. The C has library function for this. The C library function char *strtok(char *str, const char *delim) breaks string str into a series of tokens using the delimiter delim.Following is the declaration for strtok() function.char *strtok(char *str, const char *delim)It takes two parameters. The str - The contents of this string are modified and broken into smaller strings (tokens), and delim - This is the C string containing the delimiters. These may vary from one call to another. This function returns a pointer to the first token found ... Read More

string at() function in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

153 Views

In this section, we will see what is the at a () function in C++. The at() function is used to access the character at a given position.In this program, we will iterate through each character using at a () function and print them into different lines.Example Code Live Demo#include using namespace std; main() {    string my_str = "Hello World";    for(int i = 0; i

How to remove certain characters from a string in C++?

Farhan Muhamed
Updated on 09-Jun-2025 19:09:19

88K+ Views

In this section, we will see how to remove some characters from a string in C++. In C++ we can do this task very easily using erase() and remove() function. The remove function takes the starting and ending address of the string, and a character that will be removed. // Input String = "Hello TutorialsPoint" Char = 'o' // Output String = "Hell TutrialsPint" Algorithm to Remove Certain Characters from a String Here is the algorithm to remove certain characters from a string in C++: Step 1: Take a string and a character to be removed ... Read More

How to quickly reverse a string in C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

367 Views

In this section, we will see how to reverse a string very quickly using C++. For reversing there is a built-in function in the algorithm library, called reverse(). This function takes the beginning and the ending pointer of a container, then reverse the elements.Input: A number string “Hello World” Output: “dlroW olleH”AlgorithmStep 1:Take a string Step 2: reverse it using reverse() function Step 3: Print the result. Step 4: EndExample Code Live Demo#include #include using namespace std; main() {    string my_str = "This is a string to be reversed";    cout

Advertisements