Recently learn C + + containers, accumulate a bit. Set and Multiset are described below, and the structure is sorted using sort. C + + is a long way to fix it!
First, the structure of the order
Sort_struct.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm>using namespace std; typedef struct example{ int elem1; char elem2;} Example;bool Comparison (example A,example b) { return a.elem1>b.elem1;} int main () { int N; cin>>n; Vector<example> Array (N); for (int i=0;i<n;i++) { cin>>array[i].elem1>>array[i].elem2; } Sort (Array.begin (), Array.end (), comparison); for (int i=0;i<n;i++) { cout<<array[i].elem1<< "" "<<array[i].elem2<<endl; } return 0;}
Second, set application
Set, as the name implies, is the concept of a collection that does not allow repeating elements. Multiset allowed values to be repeated, it can be counted. The other uses are consistent.
Set.cpp: Defines the entry point of the console application. #include "stdafx.h" #include "iostream" #include "string" #include "set" #include <algorithm>using namespace std; int _tmain (int argc, _tchar* argv[]) {multiset<int> s;multiset<int>::iterator si; S.insert (4); S.insert (4); S.insert (3); for (Si=s.begin (); Si!=s.end (); si++) cout << *si << endl;cout<<s.count (1) <<endl; return 0;}
C + + container learning, with struct sort and set to encounter