Skip to content

Instantly share code, notes, and snippets.

@pchong90

pchong90/2_4.cpp Secret

Created June 27, 2014 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pchong90/f91f6e2c522f28cacbd4 to your computer and use it in GitHub Desktop.
Save pchong90/f91f6e2c522f28cacbd4 to your computer and use it in GitHub Desktop.
/*
Time: O(N)
Space: O(N)
*/
template <typename T>
list<T> sort(list<T> &li,const T &x){
list<T> less;
list<T> more;
typename list<T>::iterator i;
for ( i = li.begin(); i != li.end(); i++ ){
if (*i < x){
less.push_back(*i);
}
else{
more.push_back(*i);
}
}
less.splice(less.end(),more);
return less;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment