Created
October 19, 2017 14:10
-
-
Save growlnx/e9411dd63e1526a2f23471d9d237600c to your computer and use it in GitHub Desktop.
manipulando classe no vector cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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