A

@Adarsh1999

atomic and unique ptr

C++
1 year ago
#include <iostream> #include <atomic> #include <thread> #include <memory> int main() { std::atomic<int> a(0); // Initialize atomic variable 'a' to 0 // Initialize the unique_ptr to manage a new int std::unique_ptr<int> ptr = std::make

Atomic vs Pointers

C++
1 year ago
Atomic Variables vs. Pointers Atomic Variables: What they are: Atomic variables are special types of variables that ensure operations on them are atomic, meaning they are performed as a single, indivisible step. This guarantees that no other threa

Atomic Variables

C++
1 year ago
/* Atomic variables are those that can be accessed or modified by multiple threads simultaneously without causing data races. The std::atomic<T> template is used to declare atomic variables in C++. Operations on atomic variables are indivisible (a

all in one

C++
1 year ago
#include <iostream> // Base class vehicle with virtual function for sound class vehicle {//base class is needed for (polymorphism) public: virtual void sound() = 0; // Pure virtual function (abstract class) }; // The 'car' class demons

thread.detach

C++
1 year ago
#include <iostream> #include <thread> #include <chrono> // Function that will be executed by the thread void continuousThreadFunction() { auto start = std::chrono::steady_clock::now(); while (std::chrono::steady_clock::now() - start < std::

thread.join

C++
1 year ago
#include <iostream> #include <thread> #include <chrono> // Function that will be executed by the thread void continuousThreadFunction() { auto start = std::chrono::steady_clock::now(); while (std::chrono::steady_clock::now() - start < std::

Permutations of a String

C++
2 years ago
/* Problem 11: Permutations of a String Write a recursive function void permute(std::string str, int l, int r) to generate all permutations of a given string. */ #include <iostream> #include <string>

Count Ways to Reach the Nth Step

C++
2 years ago
/* Problem 10: Count Ways to Reach the Nth Step Write a recursive function int countWays(int n) to count the number of ways to reach the nth step if you can take 1, 2, or 3 steps at a time. For example, countWays(4) should return 7. */ #include

printSubsequences Backtraking best ex VIMP

C++
2 years ago
#include <iostream> #include <string> // Recursive function to print all subsequences of the given string void printSubsequences(const std::string &str, int index, std::string current) { // Base case: If we've processed all characters of the st

recursion substr

C++
2 years ago
#include <iostream> #include <string> void sub(std::string str, int start, int size){ if(size == 0){ return; } std::cout<<str[start]<<' '; sub(str, start+1, size-1); }

Reverse string

C++
2 years ago
#include <iostream> #include <string> std::string reverse(std::string &str, int start, int end){ if(start>=end){ return str; } int tmp = str[start]; str[start] = str[end];

Palindrome Check

C++
2 years ago
#include <iostream> #include <string> bool isPalindrome(const std::string& str, int start, int end) { // Base case: If start >= end, it means we've checked all characters if (start >= end) { return true; } // If characters a

Sum of array problem IMP

C++
2 years ago
#include <iostream> #include <vector> int sum(std::vector<int> &arr, int sz){ if(sz==0){ return 0; } return arr[sz-1] + sum(arr,sz-1); }

Vector vs Set vs Map

C++
2 years ago
In C++, std::set, std::map, and std::vector are three different types of containers in the Standard Template Library (STL), each serving different purposes and offering different features. Here's a comparison of these three containers: std::set

Erase in all type of vectors

C++
2 years ago
The erase function is available in multiple C++ STL containers, but its usage and behavior can vary slightly between them. Here is an overview of how erase is used in different containers: std::vector Erase: Removes elements based on iterator p

Set : push_back and pop_back for all?

C++
2 years ago
/*push_back and pop_back are available in: std::vector std::deque std::list They are not available in associative containers like std::set, std::map, std::unordered_set, and

set in vectors

C++
2 years ago
#include <iostream> #include <set> #include <algorithm> #include <iterator> #include <string> // Custom class for demonstration class Person { public: std::string name;

Set vs Vector

C++
2 years ago
In C++, both sets and vectors are part of the Standard Template Library (STL), but they serve different purposes and have different properties and usage patterns. Here’s a detailed comparison between sets and vectors: Sets (std::set) Ordered Co

Lower Bound-STL

C++
2 years ago
#include <iostream> #include <vector> #include <algorithm> #if 0 struct Person { int age; std::string name;

Vector-Erase

C++
2 years ago
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { std::vector<int> arr; int n;