You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Set initialization
set<int> s;
cout << endl;
// Set insertion
cout << "Insertion in set " << endl;
cout << endl;
for (int i = 0; i < n; i++)
{
s.insert(a[i]);
}
// Set display
cout << "Display of set element" << endl;
for (auto i = s.begin(); i != s.end(); i++)
{
cout << *i << "";
}
//Unordered Set initialization
unordered_set<int> s1;
cout << endl;
// unordered set insertion
cout << "Insertion in unordered set " << endl;
for (int i = 0; i < n; i++)
{
s1.insert(a[i]);
}
// Unordered set display
cout << "Display of unordered set element" << endl;
for (auto i = s1.begin(); i != s1.end(); i++)
{
cout << *i << "";
}
list <int> LI;
list <int>::iterator it;
//inserts elements at end of list
LI.push_back(4);
//inserts elements at beginning of list
LI.push_front(3);
//returns reference to first element of list
it = LI.begin();
//inserts 1 before first element of list
LI.insert(it,1);
//list traversalfor(it = LI.begin();it!=LI.end();it++)
{
cout<<*it<<"";
}
cout<<endl;
//reverse elements of list
LI.reverse();
//removes all occurences of 5 from list
LI.remove(5);
//removes last element from list
LI.pop_back();
//removes first element from list
LI.pop_front();
__gcd(value1, value2)
// Return gcd of two numbers, without using Euclidean Algorithm
__builtin_ffs(x)
//This function returns 1 + position of least significant 1-bit of x. Here x is int, this function with suffix 'l' gets//a long argument and with suffix 'll' gets a long long argument.
e.g. __builtin_ffs(10) = 2 because 10 is '...10 1 0' in base 2 and first 1-bit from right is at index 1 (0-based) and
function returns 1 + index.
__builtin_clz(x)
//This function returns number of leading 0-bits of x which starts from most significant bit position. x is unsigned int. If//this function with suffix 'l gets a unsigned long argument and with suffix 'll' gets a unsigned long long argument. If x =//= 0, returns an undefined value.
e.g. __builtin_clz(16) = 27 because 16 is ' ... 10000' in base-2. Number of bits in a unsigned int is 32. so function
returns 32 — 5 = 27.
__builtin_ctz(x)
//This function returns number of trailing 0-bits of x which starts from least significant bit position. x is unsigned int and//like previous function this function with suffix 'l' gets a unsigned long argument and with suffix 'll' gets a unsigned long//long argument. If x == 0, returns an undefined value.
e.g. __builtin_ctz(16) = 4 because 16 is '...1 0000 '. Number of trailing 0-bits is 4.
__builtin_popcount(x)
//This function returns number of 1-bits of x. x is unsigned int and like previous function this function with suffix 'l' gets//a unsigned long argument and with suffix 'll' gets a unsigned long long argument. If x == 0, returns an undefined value.
e.g. __builtin_popcount(14) = 3 because 14 is '... 111 0' and has three 1-bits.
__builtin_parity(x)
//This function returns 1 if number of 1-bits of x is odd, otherwise returns 0. x is unsigned int and like previous function
binary_search(arr, arr + n, key)
// This function returns true if key is present in arr[0..n-1]. Else it returns false.It is a built-in function for binary search in C++.
lower_bound(arr, arr + n, key)
// This function returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.
upper_bound(arr, arr + n, key)
// This function returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
next_permutation(arr, arr + n)
// This function returns true if the next permutation of the sequence is possible. Else it returns false. It is a built-in function for next permutation in C++.
prev_permutation(arr, arr + n)
// This function returns true if the previous permutation of the sequence is possible. Else it returns false. It is a built-in function for previous permutation in C++.