Tag: an
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;Â Â Â Â Â …
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 …
Using STL to verify brackets or parentheses combination in an expression
In this we will see how to check if a given string take valid combination of open and close brackets i.e. (4+{8-[22+8]*}] contains valid order of open and close brackets. ({5+8]) contains invalid combination of open and close brackets. Advertisements [showads ad=inside_post] Bracket combinations to be used, Frequently Asked: Using STL to verify brackets or parentheses combination in an …
Using STL to verify brackets or parentheses combination in an expressionRead More
Remove all occurences of an element from vector in O(n) complexity
Suppose we have a vector of integers and we want to delete all occurences of a number from it i.e. Let’s say vector contain following numbers 1,2,5,4,5,1,5,7,8,9. Now we want to delete all the occurences of 5 from it, so that vector contents should become – 1 2 4 1 7 8 9 . Also …
Remove all occurences of an element from vector in O(n) complexityRead More
What is an Exception and How to do Exception Handling in Java
In this article we will discuss what is an exception in Java and how to handle exception in Java. What is an exception in Java An error occurred at runtime in a Java Application is called an Exception. If a triggered Exception is not handled then it will cause the application to crash. Checkout following …
What is an Exception and How to do Exception Handling in JavaRead More
Initializing a HashSet from an Array or a Collection
In this Article we will discuss how to initialize a HashSet using a Array or a Collection. HashSet has a Constructor that receives a Collection as an argument and initializes the new Set with the elements of passed collection object. Advertisements public HashSet(Collection<? extends E> c) Initializing a HashSet with an array Suppose we need to …
Initializing a HashSet from an Array or a CollectionRead More
How to convert a HashSet into an array in Java
In this article we will discuss how to convert a HashSet in to an array. Each collection that provides a member function toArray() i.e. Advertisements public <T> T[] toArray(T[] a) It iterates through all the elements of Collection (HashSet in our case) and set the each elements in the passed argument array []a. But if array …
How to Merge an Array in a HashSet in Java
In this article we will discuss how to merge an array in a HashSet HashSet has a member function addAll() that can add a collection into to a HashSet. But this Collection should be of Same Type as of HashSet or of its Base Class. Advertisements public boolean addAll(Collection<? extends E> c)  It will add the each …
How to Search for an element in HashSet in Java
In this article we will discuss how to search for an element in HashSet. Main feature of a HashSet is Fast searching. Which it achieves using Hashing. Now suppose we want to search if an element exists in HashSet ? Advertisements It can be done using contains() member function of HashSet i.e. // It checks if the given …
How to add an element in Vector using vector::push_back
In this article we will discuss how to add element in a vector. std::vector provides a member function to push an element at the end i.e. Advertisements void push_back (const value_type& val); It will push the element in the end of list. As, this function adds the element, so it also increases the size of …
How to add an element in Vector using vector::push_backRead More