Tag: Elements
Remove Duplicate Elements from a Sorted Singly Linked List
Lets remove all duplicate elements from a sorted singly linked list. For example, Advertisements Suppose given linked list contains following elements in given order, 1, 2, 3, 4, 4, 5, 6, 7, 7, 7, 7, 9, 89 Frequently Asked: Reverse a Singly Linked List in a Single Iteration Create a Singly Linked List from an …
Remove Duplicate Elements from a Sorted Singly Linked ListRead More
How to add elements at a particular index in LinkedList
In this article we will discuss how to add elements at a particular index or position in a LinkedList in Java. add() member function of LinkedList always appends the element at the end of LinkedList. Now suppose we don’t want to add element at the end of Linked List instead of it we want to add element somewhere …
How to add elements at a particular index in LinkedListRead More
How to add elements in a LinkedList in Java
In this article we will discuss how to add elements in LinkedList and then display them. Lets create a LinkedList of String i.e. Advertisements List<String> listOfStr = new LinkedList<>(); To add elements in LinkedList we will use its add() function i.e. boolean add(E e) add() member function of LinkedList always appends the element in the …
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 erase elements from a list in c++ using iterators
In this article we will see how to erase elements from a std::list using iterators. std::list provides 2 member function to delete elements using iterators i.e. Advertisements iterator erase (const_iterator position); It deletes the element representing by passed iterator “position” and returns the iterator of element next to last deleted element. iterator erase (const_iterator first, const_iterator last); …
How to erase elements from a list in c++ using iteratorsRead More
How to remove elements from a List while Iterating
In this article we will see how to delete an element from a list while iterating through it. Removing Elements From a List while Iterating through it std::list provides a member function erase() that accepts an iterator and deletes the element pointed by that Iterator. But it makes that iterator invalid i.e. we cannot use …
How to remove elements from a List based on value or External Criterion
In this article we will discuss how to remove an element from a List by matching a value or by matching some criterion. std::list provides two member functions for removing elements based on value i.e. std::list::remove and std::list::remove_if. Advertisements Using std::list::remove to remove element by value void remove (const value_type& val); It removes all the elements …
How to remove elements from a List based on value or External CriterionRead More
How to Insert elements in an unordered_set in C++11
std::unordered_set provides the different overloaded versions of insert() member function to insert elements i.e. pair<iterator,bool> insert ( const value_type& val ); void insert ( InputIterator first, InputIterator last ); void insert ( initializer_list<value_type> il ); Let’s see each of them in detail Advertisements Inserting element in unordered_set by value For this we will use basic …
How to Insert elements in an unordered_set in C++11Read More
Different ways to insert elements in an unordered_map
In this article we will discuss the different ways to insert elements in an unordered_map. Unordered_map provides different overloaded versions of insert() member function to insert key value pairs in an unordered_map. Lets discuss them one by one. Advertisements Inserting multiple elements in unordered_map through an initializer_list unordered_map provides an overloaded version of insert that …
Different ways to insert elements in an unordered_mapRead More
c++11 unordered_map : erase elements while iterating in a loop
In this article we will discuss how to erase multiple elements from an unordered_map based on some condition and while iterating. Erasing Multiple elements from unordered_map while iterating Suppose we have an unordered_map of string and integers as key value pairs i.e. Advertisements First : 1 Second : 2 Third : 3 Fourth : 4 Fifth : 5 …
c++11 unordered_map : erase elements while iterating in a loopRead More