Skip to content

Commit 9a47f90

Browse files
authored
Merge pull request #1 from adityyyy/adityyyy-patch-1
Create vectorSort.cpp
2 parents 5e21866 + d05e346 commit 9a47f90

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CPP/vector-concepts/vectorSort.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// inbuilt sorting in vector
2+
```
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
int main(){
6+
//sort() can be used to sort array or vector or a string. gcc_sort hybrid algorithm. O(NlogN)
7+
8+
//int a[n]; sort(a,a+n);
9+
10+
//vector<int>v; sort(v.begin(), v.end());
11+
12+
//string s; sort(s.begin(), s.end());
13+
14+
//sort(ptr to 1st element, ptr to last element+1)
15+
int a[4]={5,4,1,2};
16+
//sort(a, a+3); output: 1 4 5 2
17+
18+
// sort(a, a+4); //output 1 2 4 5
19+
// for(int i=0; i<4; i++){ cout<<a[i]<<" ";}
20+
21+
vector<int>v={5,4,1,2};
22+
sort(v.begin(), v.end());
23+
for(int i=0; i<4; i++){ cout<<v[i]<<" ";}
24+
return 0;
25+
}
26+
```

0 commit comments

Comments
 (0)