#include <iostream>
#include <algorithm>
struct doPartitionOn
{
int m_key;
doPartitionOn(int key) : m_key(key) {}
bool operator()(int a)
{
return (a < m_key);
}
};
int main()
{
int arr[] = {4, 7, 3, 5, 6, 2, 9, 1, 10, 8};
for(int i = 0; i < 10; ++i)
std::cout << arr[i] << ' ';
std::cout << std::endl;
std::stable_partition(arr, arr+10, doPartitionOn(arr[0]));
for(int i = 0; i < 10; ++i)
std::cout << arr[i] << ' ';
std::cout << std::endl;
return 0;
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICNpbmNsdWRlIDxhbGdvcml0aG0+CiAgICAKICAgIHN0cnVjdCBkb1BhcnRpdGlvbk9uCiAgICB7CiAgICAJaW50IG1fa2V5OwogICAgCiAgICAJZG9QYXJ0aXRpb25PbihpbnQga2V5KSA6IG1fa2V5KGtleSkge30KICAgIAogICAgCWJvb2wgb3BlcmF0b3IoKShpbnQgYSkKICAgIAl7CiAgICAJCXJldHVybiAoYSA8IG1fa2V5KTsKICAgIAl9CiAgICB9OwogICAgCiAgICBpbnQgbWFpbigpCiAgICB7CiAgICAJaW50IGFycltdID0gezQsIDcsIDMsIDUsIDYsIDIsIDksIDEsIDEwLCA4fTsKICAgIAogICAgCWZvcihpbnQgaSA9IDA7IGkgPCAxMDsgKytpKQogICAgCQlzdGQ6OmNvdXQgPDwgYXJyW2ldIDw8ICcgJzsKICAgIAlzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwogICAgCiAgICAJc3RkOjpzdGFibGVfcGFydGl0aW9uKGFyciwgYXJyKzEwLCBkb1BhcnRpdGlvbk9uKGFyclswXSkpOwogICAgCiAgICAJZm9yKGludCBpID0gMDsgaSA8IDEwOyArK2kpCiAgICAJCXN0ZDo6Y291dCA8PCBhcnJbaV0gPDwgJyAnOwogICAgCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7CiAgICAKICAgIAlyZXR1cm4gMDsKICAgIH0K