Skip to content

Instantly share code, notes, and snippets.

@satishgoda
Last active January 1, 2016 17:29
Show Gist options
  • Save satishgoda/8177948 to your computer and use it in GitHub Desktop.
Save satishgoda/8177948 to your computer and use it in GitHub Desktop.
./a.out Abc Def Ghi ihG feD cbA
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char **arg = argv + argc -1;
while(arg > argv) {
char *sptr = *arg + strlen(*arg) - 1;
while(sptr >= *arg) {
printf("%c", *sptr);
--sptr;
}
printf("\n");
--arg;
}
printf("\n");
return EXIT_SUCCESS;
}
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <algorithm>
#include <cstdlib>
using namespace std;
template <class T>
void printReverse(const T& container)
{
auto rbiterv = container.crbegin();
while(rbiterv != container.crend()) {
auto& elem = *rbiterv++;
auto rbiterelem = elem.crbegin();
while( rbiterelem != elem.crend() ) {
cout << *rbiterelem++;
}
cout << " ";
}
cout << endl;
}
int main(int argc, char* argv[])
{
cout << "Sorting and Uniqueness for vector container" << endl;
{
vector<string> cmdlineargs { argv+1, argv+argc };
cout << boolalpha;
cout << is_sorted(cmdlineargs.begin(), cmdlineargs.end()) << endl;
//sort(cmdlineargs.begin(), cmdlineargs.end());
stable_sort(cmdlineargs.begin(), cmdlineargs.end());
cout << is_sorted(cmdlineargs.begin(), cmdlineargs.end()) << endl;
auto iter = unique(cmdlineargs.begin(), cmdlineargs.end());
cmdlineargs.erase(iter, cmdlineargs.end());
printReverse(cmdlineargs);
}
cout << endl;
cout << "Sorting and Uniqueness for list container" << endl;
{
list<string> cmdlineargs { argv+1, argv+argc };
cmdlineargs.sort();
cmdlineargs.unique();
printReverse(cmdlineargs);
}
cout << endl;
cout << "Sorting and Uniqueness for set container" << endl;
{
set<string> cmdlineargs { argv+1, argv+argc };
printReverse(cmdlineargs);
}
cout << endl;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment