Programming Articles - Page 2752 of 3366

C++ program to Convert a Decimal Number to Binary Number using Stacks

Jennifer Nicholas
Updated on 25-Apr-2025 11:53:22

4K+ Views

Decimal numbers are the set of numbers with base 10, whereas binary numbers are the numbers with base 2. In this article, we will learn how to convert a decimal number to a binary number using stack data structure in C++ program. First of all, let's understand how decimal to binary conversion technique works. Decimal to Binary Conversion Technique To convert a decimal number to a binary number follow the steps below: Divide the decimal number by 2 Save the reminder (either 1 or 0) in a place. ... Read More

C++ Program to Check for balanced paranthesis by using Stacks

Jennifer Nicholas
Updated on 28-Apr-2025 18:19:10

10K+ Views

In this article, we will learn how to check for a balanced parentheses using stack data structure in C++ program. First of all let's understand what is balanced parentheses. A string of parentheses is said to be balanced parentheses, If Every opening bracket has corresponding closing bracket of same type. The brackets are closed in correct order. For an example, we can say that the expression [{} () {()}] it is balanced. But {[}] is not balanced eventhough it contains opening and closing brackets of same type. ... Read More

Replace substring with another substring C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

2K+ Views

Here we will see how to replace substring with another substring. It replaces the portion of the string that begins at character pos and spans len characters.The structure of the replace function is like below:string& replace (size_t pos,  size_t len,  const string& str,  size_t subpos,  size_t sublen);The parameters are pos: It is an insertion point, str : It is a string object, len : It contains information about number of characters to erase.AlgorithmStep 1: Get the main string, and the string which will be replaced. And the match string Step 2: While the match string is present in the main string: Step 2.1: Replace it with the given ... Read More

Replace part of a string with another string in C++

Farhan Muhamed
Updated on 24-Apr-2025 10:12:24

6K+ Views

In this article, we will learn the different approaches to replace a part of a string with another string using a C/C++ program. The problem statement of this program is explained below: The input of this problem will be three strings. The task is to replace all the occurrence of the second string with the third string inside the first string. For example: // Input strings "C++ Course is free on Tutorialspoint" "C++" "Python" // Output String "Python Course is free on Tutorialspoint" Replace a Substring With Another String Here is the list of all ... Read More

Remove Trailing Zeros from string in C++

Farhan Muhamed
Updated on 23-Apr-2025 18:48:44

4K+ Views

Trailing zeros are the zero occuring at the end of a string. In this article, we will discuss different approaches to remove trailing zeros from a string. The below section explains the problem statement. The input of this problem is a non-empty string containing characters and numbers. Our task is to remove all the zero's appering after the last non-zero character in the string. For example: // Input string "012424000" // Output String "012424" Remove Trailing Zeros From String Here is the list of approaches to remove all the trailing zeros from a string ... Read More

Remove spaces from std::string in C++

Farhan Muhamed
Updated on 23-Apr-2025 18:48:16

17K+ Views

In this article, we will learn all the different approaches to remove the whitespaces from a standard string in C/C++. First of all, let's understand our problem statement. The input of this problem is a non-empty string containing multiple characters and whitespaces between those characters. Our task is to print the string by ignoring all the whitespaces into the output console. For example: // Input String "This is a string" // Output String "Thisisastring" Remove Whitespaces from a String in C++ Here is the list of approaches to remove all the whitespaces from a string using ... Read More

Raw string literal in C++

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

594 Views

Sometimes, in C++ when you try to print a string that containing special characters like escape sequences (), backslashes (\), or quotes(""), the output may not be as expected. To avoid this, C++ provides a feature called raw string literal. In this article, we will discuss what is raw string literal and how to use it in C++. What is Raw String Literal? A raw string literal in C++ is a type of string that preserves the formatting of the string content without changing any escape sequences such as "", "\t", or "". This is useful when you want ... Read More

Collectors minBy() method in Java 8

George John
Updated on 30-Jul-2019 22:30:25

496 Views

The minBy() method of the Collectors class in Java 8 returns a Collector that produces the minimum element according to a given Comparator, described as an OptionalThe syntax is as followsstatic Collector

LongStream mapToInt() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

1K+ Views

The mapToInt() method returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsmapToInt(LongToIntFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Declare LongStream and add some elementsLongStream longStream = LongStream.of(1000L, 13000L, 18000L);Now, use the IntStream and mapToInt()IntStream intStream = longStream.mapToInt(val -> (int) val);The following is an example to implement LongStream mapToInt() in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(1000L, 13000L, 18000L);       IntStream intStream = ... Read More

What is AbstractSequentialList class in Java?

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

436 Views

The AbstractSequentialList class provides an implementation of the List interface. For an unmodifiable list, implement the list iterator's hasNext, next, hasPrevious, previous and index methods. For a modifiable list the programmer should implement the list iterator's set method.The syntax is as followspublic abstract class AbstractSequentialList extends AbstractListTo work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;First, create an AbstractSequentialList classAbstractSequentialList absSequential = new LinkedList();Now, add elementsabsSequential.add("Accessories"); absSequential.add("Home Decor"); absSequential.add("Books"); bsSequential.add("Stationery");Let us see an example to implement the AbstractSequentialList class in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] ... Read More

Advertisements