Skip to content

Instantly share code, notes, and snippets.

@gnarula
Created December 2, 2016 20:10
Show Gist options
  • Save gnarula/6919307c7da4e11f8b50c79bc54089d2 to your computer and use it in GitHub Desktop.
Save gnarula/6919307c7da4e11f8b50c79bc54089d2 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
class LexGen {
public:
int length;
LexGen(int l) {
length = l;
}
class iterator {
int i;
int c;
int len;
public:
string str;
iterator(string s, int l) {
str = s;
c = 0;
len = l;
}
const string &operator*() {
return str;
}
void operator++() {
int i = len - 1;
while(i >= 0 && str[i] == 'd') {
str[i] = 'a';
i--;
}
if(i >= 0) {
str[i]++;
}
c++;
}
bool operator!=(const iterator &r) {
return str.compare(r.str) != 0;
}
};
iterator begin() {
iterator it("aaa", length);
return it;
}
iterator end() {
return iterator("ddd", length);
}
};
int main() {
LexGen lg(3);
for(auto it = lg.begin(); it != lg.end(); ++it) {
cout << *it << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment