FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
C-Plus-Plus/others/vector_important_functions.cpp at master · SelfCodeLearning/C-Plus-Plus · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SelfCodeLearning
/
C-Plus-Plus
Public
forked from
TheAlgorithms/C-Plus-Plus
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
C-Plus-Plus
/
others
/
vector_important_functions.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (35 loc) · 1.07 KB
Breadcrumbs
C-Plus-Plus
/
others
/
vector_important_functions.cpp
Copy path
File metadata and controls
45 lines (35 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
A C++ program to demonstrate working of sort(),
//
reverse()
#
include
<
algorithm
>
#
include
<
iostream
>
#
include
<
vector
>
#
include
<
numeric
>
//
For accumulate operation
using
namespace
std
;
int
main
()
{
//
Initializing vector with array values
int
arr[] = {
10
,
20
,
5
,
23
,
42
,
15
};
int
n =
sizeof
(arr)/
sizeof
(arr[
0
]);
vector<
int
>
vect
(arr, arr+n);
cout <<
"
Vector is:
"
;
for
(
int
i=
0
; i<n; i++)
cout << vect[i] <<
"
"
;
//
Sorting the Vector in Ascending order
sort
(vect.
begin
(), vect.
end
());
cout <<
"
\n
Vector after sorting is:
"
;
for
(
int
i=
0
; i<n; i++)
cout << vect[i] <<
"
"
;
//
Reversing the Vector
reverse
(vect.
begin
(), vect.
end
());
cout <<
"
\n
Vector after reversing is:
"
;
for
(
int
i=
0
; i<
6
; i++)
cout << vect[i] <<
"
"
;
cout <<
"
\n
Maximum element of vector is:
"
;
cout << *
max_element
(vect.
begin
(), vect.
end
());
cout <<
"
\n
Minimum element of vector is:
"
;
cout << *
min_element
(vect.
begin
(), vect.
end
());
//
Starting the summation from 0
cout <<
"
\n
The summation of vector elements is:
"
;
cout <<
accumulate
(vect.
begin
(), vect.
end
(),
0
);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL