Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Last active May 27, 2016 13:05
Show Gist options
  • Select an option

  • Save indatawetrust/e7bc553c4565729e955feff5302015a8 to your computer and use it in GitHub Desktop.

Select an option

Save indatawetrust/e7bc553c4565729e955feff5302015a8 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
class Array
{
vector<map<string,string>> array;
public:
int length(){ return array.size(); };
int indexOf(string key)
{
if(length() > 0){
int i = -1;
for(auto data:this->array){
i++;
if(data.count(key) > 0){
return i;
break;
}else{
return -1;
}
}
}else{
return -1;
}
}
void push(string key, string value)
{
if(indexOf(key) == -1){
map<string,string> data;
data.insert(pair<string,string>(key,value));
this->array.push_back(data);
}
}
string get(string key)
{
return indexOf(key) == -1
? "key not found" : this->array.at(indexOf(key))[key];
}
};
int main(int argc,char** argv)
{
Array array;
array.push("url","https://gist.github.com/");
cout << "url : " << array.get("url") << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment