Found 34475 Articles for Programming

C++ Program to Implement Set_Union in STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

524 Views

The union of two sets is created by the elements that are present in either one of the sets, or in both. Elements from the second set that has the same element in the first set are not copied to the resulting set.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.    Initialize st= set_union (set1, set1 + n, set2, set2 +n, v.begin()))    Print the elements. End.Example Code Live Demo#include #include #include using namespace std; int main () {    int set1[] = {5, ... Read More

C++ Program to Implement Set_Symmetric_difference in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

201 Views

This is a c++ program to implemet set_symmetric_difference. The symmetric difference of two sets is built by the elements that are present in one of the sets, but not in the other.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.   Initialize st = set_symmetric_difference (set1, set1 + n, set2, set2 +n, v.begin()))    Print the elements obtained after symmetric_difference of two sets End.Example Code#include #include #include using namespace std; int main () {    int set1[] = {5, 6, 7, 8, 9, 10};   ... Read More

C++ Program to Implement Set_Intersection in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

474 Views

The intersection of two sets is formed only by the elements those are common in both sets. The elements copied by the function come always from the first set in the same order. The elements in the both the sets shall already be ordered.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.    Initialize st = set_intersection (set1, set1 + n, set2, set2 +n, v.begin()))    Print the intersection between two sets. End.Example Code#include #include #include using namespace std; int main () {   ... Read More

C++ Program to Implement Set_Difference in STL

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

740 Views

The difference of two sets is formed only by the elements that are present in the first set, not in the second set. The elements copied by the function come always from the first set in the same order. The elements in both the sets shall already be ordered.Common set operations are −Set UnionSet IntersectionSymmetric Set Difference or Exclusive-ORSet Difference or SubtractionAlgorithmBegin    Declare set vector v and iterator st.    Initialize st = set_difference (set1, set1 + n, set2, set2 +n, v.begin()))    Print the number of elements different between two sets. End.Example Code#include #include #include using ... Read More

C++ Program to Implement Set in STL

Nitya Raut
Updated on 30-Jul-2019 22:30:25

467 Views

Set is abstract data type in which each element has to be unique, because the value of the element identifies it. The value of the element cannot be modified once it is added to the set, but it is possible to remove and add the modified value of that element.Functions and descriptions:Functions used here:    st.size() = Returns the size of set.    st.insert() = It is used to insert elements to the set.    st.erase() = To delete the element from the set.    st.find() = Returns an iterator to the search element in the set if found, else ... Read More

C++ Program to Implement Queue in STL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

636 Views

A queue is a linear structure which follows First In First Out (FIFO) order in which the operations are performed on the elements of the queue.AlgorithmFunctions used here:    q.size() = Returns the size of queue.    q.push() = It is used to insert elements to the queue.    q.pop() = To pop out the value from the queue.    q.front() = Returns the front element of the array.    q.back() = Returns the back element of the array.Example Code#include #include #include #include using namespace std; int main() {    queue q;    int c, i;    while (1) {       cout

Create KeyValue Tuple from another collection in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

53 Views

To create KeyValue tuple from another collection, use the fromCollection() method. We will be creating the tuple from List collection. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package.import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples.Steps: How to run JavaTuples program in EclipseThe following ... Read More

Create LabelValue Tuple from another collection in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

58 Views

To create LabelValue tuple from another collection, use the fromCollection() method or the fromArray() method. Here, we will be creating LabelValue from List, therefore use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package.import org.javatuples.LabelValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples.Steps: How ... Read More

Create Decade Tuple using with() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

60 Views

To create a Decade Tuple in Java, you can use the with() method. Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package.import org.javatuples.Decade;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples.Steps: How to run JavaTuples program in EclipseThe following is an example to create Decade Tuple ... Read More

The listIterator() method of AbstractList class in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

83 Views

The listIterator() method of the AbstractList class in Java is used to return a list iterator over the elements in this list.The syntax is as follows.public ListIterator listIterator()Here, ListIterator is an iterator for lists.To work with the AbstractList class, import the following package.import java.util.AbstractList;For ListIterator, import the following package.import java.util.ListIterator;The following is an example to implement listIterator() method of the AbstractlList class in Java.Example Live Demoimport java.util.ArrayList; import java.util.ListIterator; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList();       myList.add(75);       myList.add(100);       ... Read More

Advertisements