Skip to content

Instantly share code, notes, and snippets.

@growlnx
Created October 19, 2017 14:10
Show Gist options
  • Select an option

  • Save growlnx/e9411dd63e1526a2f23471d9d237600c to your computer and use it in GitHub Desktop.

Select an option

Save growlnx/e9411dd63e1526a2f23471d9d237600c to your computer and use it in GitHub Desktop.
manipulando classe no vector cpp
#include "bits/stdc++.h"
using namespace std;
class No{
public:
No *dir, *esq;
int quantidade;
char letra;
No(No *dir,No *esq,int quantidade,char letra){
this->dir = dir;
this->esq = esq;
this->quantidade =quantidade;
this->letra = letra;
}
};
int main(){
vector<No> arvore;
arvore.push_back(No(nullptr,nullptr,4,'d'));
arvore.push_back(No(nullptr,nullptr,22,'b'));
arvore.push_back(No(nullptr,nullptr,10,'c'));
arvore.push_back(No(nullptr,nullptr,-2,'a'));
for(auto x : arvore ){
cout << x.quantidade<< " " << x.letra << endl;
}
sort(arvore.begin(), arvore.end(), [](No &a , No &b)->bool{
return a.quantidade < b.quantidade;
});
cout << endl << endl;
for(auto x : arvore ){
cout << x.quantidade<< " " << x.letra << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment