Skip to content

Instantly share code, notes, and snippets.

@AALEKH
Created August 10, 2016 05:31
Show Gist options
  • Select an option

  • Save AALEKH/e5fb39ec9a2da85274d66d283c308e7a to your computer and use it in GitHub Desktop.

Select an option

Save AALEKH/e5fb39ec9a2da85274d66d283c308e7a to your computer and use it in GitHub Desktop.
A sample Window implementation
// make_tuple example
#include <iostream>
#include <tuple>
#include <functional>
#include <vector>
using namespace std;
vector<tuple<int, int, int, int>> create_tuple()
{
// auto first = std::make_tuple (10,'a'); // tuple < int, char >
tuple<int, int, int, int> aoo;
vector<tuple<int, int, int, int>> output;
int iSecret, ist;
for (int i = 0; i < 100; i++)
{
iSecret = rand() % 100 + 1;
ist = rand() %50 + 1;
output.push_back(std::make_tuple(i+ist, i+ist+iSecret, i+iSecret, i+iSecret-ist));
}
return output;
}
int main(){
int ele = -120;
vector<tuple<int, int, int, int>> print;
vector<vector<tuple<int, int, int, int>>> axo;
vector<tuple<int, int, int, int>> axc;
vector<int> ifpresent;
print = create_tuple();
sort(print.begin(), print.end(),
[](const tuple<int, int, int, int>& a,
const tuple<int,int, int, int>& b) -> bool
{
return std::get<2>(a) > std::get<2>(b);
});
for (int i = 0; i < 100; i++)
{
std::cout << "Index: " << i <<" First " << std::get<0>(print[i]) <<" Second " << std::get<1>(print[i]) <<" Third " << std::get<2>(print[i]) <<" Fourth " << std::get<3>(print[i]) << endl;
}
for (int i = 0; i < 100; i++) {
ele = std::get<2>(print[i]);
axc.push_back(print[i]);
if(!(std::find(ifpresent.begin(), ifpresent.end(), ele) != ifpresent.end())) {
ifpresent.push_back(ele);
cout << "Element is: " << ele << endl;
for(int n = i+1; n < 100; n++){
if(ele == std::get<2>(print[n])) {
axc.push_back(print[n]);
}
}
axo.push_back(axc);
axc.clear();
}
}
for(int j = 0; j < axo.size(); j++){
for(int k = 0; k < axo[j].size(); k++){
cout << "Part of group: " << std::get<2>(axo[j][k]) << " First " << std::get<0>(axo[j][k]) <<" Second " << std::get<1>(axo[j][k]) <<" Third " << std::get<2>(axo[j][k]) <<" Fourth " << std::get<3>(axo[j][k]) << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment