C++ Program to Implement Deque in STL

Farhan Muhamed
Updated on 06-May-2025 18:20:01

515 Views

Deque or Double Ended Queue is a special type of queue where we can insert and delete elements from both front and back. In this article, we will learn how to use deque from C++ STL (Standard Template Library). What is Deque? Deque is a linear data structure in which the insertion and deletion operations can be performed at both the ends (front and rear). Meaning, the data can be inserted at both front and rear positions and can be deleted from both front and rear positions. This gives more flexibility compared to a normal queue which supports only ... Read More

Vector Resize vs Vector Reserve in C++

karthikeya Boyini
Updated on 06-May-2025 17:31:12

1K+ Views

Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically. The main difference between vector resize() and vector reserve() is that resize() is used to change the size of vector where reserve() doesn’t. reserve() is only used to store at least the number of the specified elements without having to reallocate memory. But in resize() if the number is smaller than the current number then it resizes the memory and deletes the excess space over it. C++ vector::resize() The resize() is used to change the actual ... Read More

Convert List of Characters to String in Java

Aishwarya Naglot
Updated on 06-May-2025 16:36:36

1K+ Views

In this article, we will learn to convert a list of characters to strings in Java. Sometimes, when we handle character-based data structures, we need to convert a list of characters into a string. Problem Statement Given a list of characters, the task is to convert it into a single string where the order of characters remains unchanged. Input:  list = Arrays.asList('W', 'e', 'l', 'c', 'o', 'm', 'e'); Output: Welcome Methods to Convert a List of Characters to a String The following are the different approaches to convert a list of characters to a string in Java - ... Read More

Use of Return Statement in Python

Sarika Singh
Updated on 06-May-2025 10:57:21

4K+ Views

The return statement in Python is used to return a value or a set of values from a function. When a return statement is encountered in a function, the function execution is stopped, and the value specified in the return statement is returned to the caller. Without it, a function simply executes its code but doesn't provide any result back. The return statement allows a function to output a result which can be used later in the program. Why Use the Return Statement? You should use the return statement in the following cases − To ... Read More

Implement Wheel Sieve to Generate Prime Numbers in C++

Ravi Ranjan
Updated on 05-May-2025 18:42:57

536 Views

The wheel Sieve method is used to find the prime numbers within a given range. Wheel factorization is a graphical method for manually performing a preliminary to the Sieve of Eratosthenes that separates prime numbers from composites. In this method, prime numbers in the innermost circle have their multiples in similar positions as themselves in the other circles, forming spokes of primes and their multiples. Multiple of these prime numbers in the innermost circle form spokes of composite numbers in the outer circles. In this article, we have set the limit to 100. Our task is to implement the ... Read More

Implement Sieve of Atkin to Generate Prime Numbers in C++

Ravi Ranjan
Updated on 05-May-2025 18:42:43

754 Views

The Sieve of Atkin is a modern algorithm for finding all prime numbers up to a specified integer. It follows three simple steps to find the prime numbers. It uses three quadratic expressions that remove the composite numbers. After this, we remove the multiples of squares of already existing prime numbers and at the end, we return the prime numbers. In this article, we have set the limit to '30'. Our task is to implement the Sieve of Atkin method to generate all the prime numbers up to the limit in C++. Here is an example of prime numbers up ... Read More

Implement Sieve of Eratosthenes to Generate Prime Numbers in C++

Ravi Ranjan
Updated on 05-May-2025 18:42:30

3K+ Views

The Sieve of Eratosthenes algorithm is one of the most efficient ways to find prime numbers smaller than n when n is smaller than around 10 million. It follows a simple process of marking the multiples of already prime numbers as false i.e. non-prime numbers. In this article, we have a given number as 'num'. Our task is to find all the prime numbers less than or equal to num using the Sieve of Eratosthenes algorithm in C++. Example Here is an example to find prime numbers less than 10: Input: num = 10 Output: 2 3 5 7 ... Read More

Difference Between cerr and clog Streams in C++

Akansha Kumari
Updated on 05-May-2025 18:39:52

1K+ Views

cerr and clog are both objects of the stderr(standard error) stream, which is used to display error messages or diagnostics. In this article, we will learn the difference between these two in more detail. Further, the description of the cout object is also given to get a clearer picture. Unbuffered standard error stream (cerr) The cerr is the standard error stream, which is used to output the errors. This is also an instance of the ostream (as iostream means input/output stream) class. As cerr is unbuffered, therefore it's used when we need to display the error message instantly. It doesn't ... Read More

Pass an Array by Value in C

Tapas Kumar Ghosh
Updated on 05-May-2025 18:36:54

1K+ Views

In C programming, when you pass an array by value, you are not sending the entire array. Instead of this, it passes a pointer to the first element. So, this shows functions directly work with an original array but do not copy. Note: If we make any changes to the array element, those changes will be reflected in the original array outside the function as well. Syntax There are two syntaxes for passing an array by value as follows: i. The syntax of array notation for passing array to function. void function_name(data_type array_name[], int size) { // Function ... Read More

Convert a Single Character to String in C++

Tapas Kumar Ghosh
Updated on 05-May-2025 18:36:35

428 Views

In C++, a single character is represented using a single quotation (' ') while a string is represented using a double quotation (" "). To change the single character into a string, use approaches like string_constructor, push_back(), etc., that solve the conversion. Example Input: ch = 'A' Output: str = A // "A" So, character A is converted to a string. C++ provides various approaches to convert single character into string as follows: Using string constructor Using push_back() Using stringstream ... Read More

Advertisements