Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <gsl/span>
- typedef std::vector<int> IntVec;
- typedef gsl::span<int> IntSpan;
- // - - - - - - - - - - - - -
- void OldBubble(IntVec& v) {
- for(int a=0; a<10; ++a) { //using bubble sort algorithm here
- for(int b=a+1; b<10; ++b) {
- if (v[a] > v[b]) { std::swap(v[a],v[b]); }
- }
- }
- }
- void SpanBubble(IntSpan v) {
- int i=0;
- for(int& a : v) {
- ++i;
- for(auto& b : v.subspan(i) ) {
- if ( a > b) { std::swap(a,b); }
- }
- }
- }
- // - - - - - - - - - - - - -
- //int arr [10] {3,7,6,2,8,4,5,5,9,7};
- IntVec vec {3,7,6,2,8,4,5,5,9,7};
- IntVec vek = vec;
- int main() {
- SpanBubble (vec);
- OldBubble (vek);
- return 0;
- }
Add Comment
Please, Sign In to add comment