Back
Close

C++ Runnable Snippets

Marchete
31K views

Sorting a vector

  • Sorting an int vector
#include <bits/stdc++.h>
using namespace std;
vector<int> Data = {3,15,-88,-3,88,103,32,1};
void printData(const string& MSG){
cout << MSG<<" is: {";
for (auto& d:Data) cout << d<<",";
cout << "}"<< endl;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • Sorting an object vector by some field
#include <bits/stdc++.h>
using namespace std;
class Pod{
public:
float x,y;
float vx,vy;
Pod(){ } //No initialization
Pod(float _x,float _y, float _vx, float _vy){
x=_x;y=_y;vx=_vx;vy=_vy;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Lambda functions are more compact, aimed as small, simple functions. But harder to reuse.

Check http://en.cppreference.com/w/cpp/algorithm/sort for more info

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants