Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

These are important stl properties and function added to the repo #6981

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[10] = {11, 23, 53, 64, 75, 16, 27, 88, 69, 10}; // array of size 10

// 1. sort
sort(a, a + 10); // sort(starting address, ending address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 2. reverse
reverse(a, a + 10); // reverse(starting address, ending address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 3. min_element
cout << *min_element(a, a + 10) << endl; // min_element(starting address, ending address)

// 4. max_element
cout << *max_element(a, a + 10) << endl; // max_element(starting address, ending address)

// 5. accumulate
cout << accumulate(a, a + 10, 0) << endl; // accumulate(starting address, ending address, initial value)

// 6. count
cout << count(a, a + 10, 10) << endl; // count(starting address, ending address, element to be counted)

// 7. find
cout << *find(a, a + 10, 10) << endl; // find(starting address, ending address, element to be found)

// 8. binary_search
cout << binary_search(a, a + 10, 10) << endl; // binary_search(starting address, ending address, element to be found)

// 9. lower_bound
cout << *lower_bound(a, a + 10, 10) << endl; // lower_bound(starting address, ending address, element to be found)

// 10. upper_bound
cout << *upper_bound(a, a + 10, 10) << endl; // upper_bound(starting address, ending address, element to be found)

// 11. rotate
rotate(a, a + 3, a + 10); // rotate(starting address, new starting address, ending address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 12. next_permutation
next_permutation(a, a + 10); // next_permutation(starting address, ending address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 13. prev_permutation
prev_permutation(a, a + 10); // prev_permutation(starting address, ending address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 14. swap
swap(a[0], a[9]); // swap(element 1, element 2)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 15. swap_ranges
swap_ranges(a, a + 5, a + 5); // swap_ranges(starting address 1, ending address 1, starting address 2)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 16. reverse_copy
reverse_copy(a, a + 10, a); // reverse_copy(starting address, ending address, starting address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 17. rotate_copy
rotate_copy(a, a + 3, a + 10, a); // rotate_copy(starting address, new starting address, ending address, starting address)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 18. is_sorted
cout << is_sorted(a, a + 10) << endl; // is_sorted(starting address, ending address)

// 19. is_partitioned
cout << is_partitioned(a, a + 10, [](int x)
{ return x % 2 == 0; })
<< endl; // is_partitioned(starting address, ending address, condition)

// 20. partition
partition(a, a + 10, [](int x)
{ return x % 2 == 0; }); // partition(starting address, ending address, condition)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 21. stable_partition
stable_partition(a, a + 10, [](int x)
{ return x % 2 == 0; }); // stable_partition(starting address, ending address, condition)
for (int i = 0; i < 10; i++)
{
cout << a[i] << " ";
}
cout << endl;

// 22. partition_point
// auto it = partition_point(a, a + 10, [](int x)
// { return x % 2 == 0; }); // partition_point(starting address, ending address, condition)
// cout << *it << endl;

// 23. random_shuffle
random_shuffle(a, a + 10); // random_shuffle(starting address, ending address)

// 24. shuffle
shuffle(a, a + 10, default_random_engine()); // shuffle(starting address, ending address, random engine)

// 25. max
cout << max(2, 3) << endl; // max(element 1, element 2)

// 26. min
cout << min(2, 3) << endl; // min(element 1, element 2)

// 27. memset
int b[10];
memset(b, 0, sizeof(b)); // memset(starting address, value to be filled, size of the array)

// 28. is_permutation
cout << is_permutation(a, a + 10, b) << endl; // is_permutation(starting address 1, ending address 1, starting address 2)

// 29. next
// auto it = std::next(std::begin(a), 1); // get iterator to second element of array a

// 30. prev
// auto it = std::prev(std::end(a), 1); // get iterator to last element of array a

// 31. iota
iota(a, a + 10, 1); // iota(starting address, ending address, value to be filled)

// 32. gcd
cout << __gcd(10, 20) << endl; // __gcd(element 1, element 2)//info: __gcd is a inbuilt function for finding gcd of two numbers

// 33. lcm
// cout << lcm(10, 20) << endl; // lcm(element 1, element 2)

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s = "Hello World";
cout << s << endl;

// 1. sort
sort(s.begin(), s.end()); // sort(starting address, ending address)
cout << s << endl;

// 2. reverse
reverse(s.begin(), s.end()); // reverse(starting address, ending address)
cout << s << endl;

// 3. min_element
cout << *min_element(s.begin(), s.end()) << endl; // min_element(starting address, ending address)

// 4. max_element
cout << *max_element(s.begin(), s.end()) << endl; // max_element(starting address, ending address)

// 5. accumulate
cout << accumulate(s.begin(), s.end(), 0) << endl; // accumulate(starting address, ending address, initial value)//info: accumulate() is used to find the sum of elements in a container.

// 6. count
cout << count(s.begin(), s.end(), 'l') << endl; // count(starting address, ending address, element to be counted) //info: count() is used to count the number of occurrences of an element in a container.

// 7. find
cout << *find(s.begin(), s.end(), 'l') << endl; // find(starting address, ending address, element to be found)//info: find() is used to find the first occurrence of an element in a container.

// 8. binary_search
cout << binary_search(s.begin(), s.end(), 'l') << endl; // binary_search(starting address, ending address, element to be found)

// 9. lower_bound
cout << *lower_bound(s.begin(), s.end(), 'l') << endl; // lower_bound(starting address, ending address, element to be found)//info: lower_bound() is used to find the position of the first element in a container which is not less than a specified value.

// 10. upper_bound
cout << *upper_bound(s.begin(), s.end(), 'l') << endl; // upper_bound(starting address, ending address, element to be found)

// 11. rotate
rotate(s.begin(), s.begin() + 3, s.end()); // rotate(starting address, new starting address, ending address)
cout << s << endl;

// 12. next_permutation
next_permutation(s.begin(), s.end()); // next_permutation(starting address, ending address)
cout << s << endl;

// 13. substr
cout << s.substr(3, 4) << endl; // substr(starting index, length)

// 14. find_first_of
cout << s.find_first_of("l") << endl; // find_first_of(string to be found)

// 15. find_last_of
cout << s.find_last_of("l") << endl; // find_last_of(string to be found)

// 16. find_first_not_of
cout << s.find_first_not_of("l") << endl; // find_first_not_of(string to be found)

// 17. find_last_not_of
cout << s.find_last_not_of("l") << endl; // find_last_not_of(string to be found)

// 18. stoi
string s1 = "123";
cout << stoi(s1) << endl; // stoi(string to be converted)

// 19. to_string
int x = 123;
cout << to_string(x) << endl; // to_string(int to be converted)

// 20. isdigit
cout << isdigit(s[0]) << endl; // isdigit(character to be checked)

// 21. isalpha
cout << isalpha(s[0]) << endl; // isalpha(character to be checked)

// 22. isalnum
cout << isalnum(s[0]) << endl; // isalnum(character to be checked)

// 23. islower
cout << islower(s[0]) << endl; // islower(character to be checked)

// 24. isupper
cout << isupper(s[0]) << endl; // isupper(character to be checked)

// 25. isxdigit
cout << isxdigit(s[0]) << endl; // isxdigit(character to be checked)

// 26. isgraph
cout << isgraph(s[0]) << endl; // isgraph(character to be checked)

// 27. isprint
cout << isprint(s[0]) << endl; // isprint(character to be checked)

// 28. iscntrl
cout << iscntrl(s[0]) << endl; // iscntrl(character to be checked)

// 29. isspace
cout << isspace(s[0]) << endl; // isspace(character to be checked)

// 30. isblank
cout << isblank(s[0]) << endl; // isblank(character to be checked)

// 31. ispunct
cout << ispunct(s[0]) << endl; // ispunct(character to be checked)

// 32. toupper
cout << toupper(s[0]) << endl; // toupper(character to be converted)

// 33. tolower
cout << tolower(s[0]) << endl; // tolower(character to be converted)

// 34. getline
getline(cin, s); // getline(input stream, string)

// 35. stringstream
stringstream ss;
ss << s; // ss << string
ss >> s; // ss >> string

// 36. stringstream
stringstream ss1(s); // ss(string)

// 37. stringstream
stringstream ss2(s, ios_base::in | ios_base::out); // ss(string, mode)

// 38. stringstream
stringstream ss3(s, ios_base::in); // ss(string, mode)

// 39. stringstream
stringstream ss4(s, ios_base::out); // ss(string, mode)

// 40. stringstream
stringstream ss5(ios_base::in | ios_base::out); // ss(mode)

// 41. stringstream
stringstream ss6(ios_base::in); // ss(mode)

// 42. stringstream
stringstream ss7(ios_base::out); // ss(mode)

// 43. stringstream
stringstream ss8; // ss

// 44. stringstream
stringstream ss9(ios_base::app); // ss(mode)

// 45. stringstream
stringstream ss10(ios_base::ate); // ss(mode)

// 46. stringstream
stringstream ss11(ios_base::binary); // ss(mode)

// 47. stringstream
stringstream ss12(ios_base::trunc); // ss(mode)

// 48. stringstream
stringstream ss13(ios_base::in | ios_base::out | ios_base::binary); // ss(mode)

// 49. stringstream
stringstream ss14(ios_base::in | ios_base::out | ios_base::ate); // ss(mode)

// 50. stringstream
stringstream ss15(ios_base::in | ios_base::out | ios_base::app); // ss(mode)

// 51. stringstream
stringstream ss16(ios_base::in | ios_base::out | ios_base::trunc); // ss(mode)

// 52. stringstream
stringstream ss17(ios_base::in | ios_base::out | ios_base::binary | ios_base::ate); // ss(mode)

// 53. stringstream
stringstream ss18(ios_base::in | ios_base::out | ios_base::binary | ios_base::app); // ss(mode)

// 54. stringstream
stringstream ss19(ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc); // ss(mode)

// 55. stringstream
stringstream ss20(ios_base::in | ios_base::out | ios_base::binary | ios_base::ate | ios_base::app); // ss(mode)

// 56. stringstream
stringstream ss21(ios_base::in | ios_base::out | ios_base::binary | ios_base::ate | ios_base::trunc); // ss(mode)

// 57. stringstream
stringstream ss22(ios_base::in | ios_base::out | ios_base::binary | ios_base::app | ios_base::trunc); // ss(mode)

// 58. stringstream
stringstream ss23(ios_base::in | ios_base::out | ios_base::binary | ios_base::ate | ios_base::app | ios_base::trunc); // ss(mode)

// 59.
return 0;
}
Loading