Create a Singly Linked List from an array
Suppose we have an int array and we want to create it into a singly linked list from it.
Create a Singly Linked List from an array Read More »
Suppose we have an int array and we want to create it into a singly linked list from it.
Create a Singly Linked List from an array Read More »
In modern C++ programming, smart pointers provides automatic memory management. Among these smart pointers, shared_ptr is widely used because it takes care of releasing memory when it is no longer needed, thanks to reference counting. However, misusing shared_ptr can lead to issues like memory leaks, especially in complex data structures such as binary trees. Let’s
What is weak_ptr in Modern C++ & why do we need it? Read More »
In modern C++, std::shared_ptr is a smart pointer that manages shared ownership of a dynamically allocated object. It is part of the C++ Standard Library’s memory header. Shared pointers keep track of how many objects own a particular resource and automatically delete the resource when there are no owners left. However, if not used carefully,
How not to use Smart Pointers in C++? Read More »
In this article, we will compare the C++11 Smart Pointer implementation shared_ptr with a normal pointer. Missing ++, – – and [] operators in shared_ptr While shared_ptr in C++ offers robust memory management and facilitates collaborative ownership of resources, it intentionally lacks some operators that are available to raw pointers. This is primarily to prevent
Smart Pointer vs Raw Pointer in C++ Read More »
In this article, we will discuss when and how to use a custom deleter with shared_ptr in Modern C++. Using shared_ptr with Arrays in C++ When a shared_ptr object goes out of scope, its destructor is indeed called. Within its destructor, the reference count is decremented by one. If the new value of the reference
Shared_ptr & Custom Deleter in Modern C++ Read More »
In this article, we will discuss one of the most used Smart Pointers in C++: shared_ptr. What is std::shared_ptr<>? The std::shared_ptr is a smart pointer class provided by C++11. Multiple std::shared_ptr objects can point to same dynamically allocated memory. It ensures automatic deletion of the associated memory when there are no more shared_ptr instances pointing
What is shared_ptr in C++? Read More »
Many times we need to perform certain tasks and also group them.
Task Grouping Using Composite Design Pattern Read More »
Many times we need to search for some specific paths in a binary tree from top to bottom. Lets design a code to find out all paths in a binary tee.
Finding paths in a Binary Tree Read More »
Change the left and right pointers of each node in Binary search Tree to make it a sorted doubly linked list.
Converting a Binary Search Tree to a Sorted Doubly Linked List Read More »