Tag: Create
C++11 Smart Pointer – Part 4: Create shared_ptr objects carefully
We should create shared_ptr objects carefully. Checkout below two cases, [showads ad=inside_post] Advertisements 1.) Try not to use same raw pointer for creating more than one shared_ptr object because in that case different shared_ptr objects will not get to know that they are sharing the pointer with any other shared_ptr objects. How this can create …
C++11 Smart Pointer – Part 4: Create shared_ptr objects carefullyRead More
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. Singly Linked List Our Node structure is, Advertisements struct node { int value; node * nextPtr; node(int val) { value = val; nextPtr = NULL; …
C++11 Multithreading – Part 1 : Three Different ways to Create Threads
In this article we will discuss how to create threads in C++11 using std::thread. Introduction to C++11 Thread Library Original C++ Standard supported only single thread programming. The new C++ Standard (referred to as C++11 or C++0x) was published in 2011. In C++11 a new thread library is introduced. Advertisements Compilers Required: Linux: gcc 4.8.1 …
C++11 Multithreading – Part 1 : Three Different ways to Create ThreadsRead More
Create a Binary Search Tree from an array
Lets discuss how to create a BST From an array. Advertisements Tree’s node structure is as follows, typedef struct node { int value; node * pLeft; node * pRight; node(int val = 0) { value = val; pRight = NULL; pLeft = NULL; } }node; Now create a getBST function that accepts an integer pointer …
How to create and add elements in a HashSet in Java
+In this article we will discuss how to create a HashSet of integers and add elements in it. Creating a HashSet Object for integer // Create a HashSet of int HashSet<Integer> setOfInts = new HashSet<>(); This hashset object can contain only unique integers. Advertisements Adding Element in a HashSet To add an element in a …
How to create and add elements in a HashSet in JavaRead More
How to Create a Thread in Java using Runnable Interface
In this article we will discuss how to create a thread in Java using Runnable Interface. Why do we need Runnable Interface We create threads to execute certain tasks in parallel. Every task is different from another Task. Tasks are usually encapsulated in its own class. Therefore, extending our Task class from Thread is not only an incorrect …
How to Create a Thread in Java using Runnable InterfaceRead More
POSIX : How to create a thread | pthread_create() example & Tutorial
In this article we will discuss how to create a thread in C or C++ using POSIX Thread Library on Linux. Creating a thread will create a separate execution unit with in the same process. Each thread will have its own, Advertisements Stack Thread ID Program counter Thread Local Storage Each of thread shares the …
POSIX : How to create a thread | pthread_create() example & TutorialRead More
C++11: How to create Vector of Thread Objects ?
In this article we will create a vector thread and discuss things which we need to take care while using it. Creating & Using vector of std::thread Let’s Create a vector of std::thread objects i.e. Advertisements // Create a vector of threads std::vector<std::thread> vecOfThreads; Now let’s create a std::function<> object that we will pass to …
Python : How to create a list and initialize with same values
In this article we will discuss how to create a list and initialise with same values. Creating a list of same values by [] and multiply Suppose we want to create a list of strings, which contains 20 same strings i.e. ‘Hi’ Advertisements [‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, ‘Hi’, …
Python : How to create a list and initialize with same valuesRead More
Python : 6 Different ways to create Dictionaries
In this article, we will discuss different ways to create dictionary objects in python. What is a dictionary? dictionary is an associative container that contains the items in key/value pairs. For example, we if want to track the words and their frequency count in an article like, Advertisements “Hello” occurs 7 times “hi” occurs 10 times …