@2017libin
2019-06-16T16:55:32.000000Z
字数 1053
阅读 68
acm
# include<iostream># include<string># include<algorithm>#include<numeric>#include <vector>#include <queue>using namespace std;int mid[32], fr[32];struct node {int l, r;}a[1002];//建一个以一个mid[la,ra],fr[lb,rb]所确定的数int build(int la, int ra, int lb, int rb){if (la > ra)return 0;//fr:前序,b序列//mid:中序,a序列int rt = fr[lb], p1, p2;p1 = la;//找到pl对应的前序的第一个节点,也就是树的根。while (mid[p1] != rt) p1++;p2 = p1 - la;a[rt].l = build(la, p1 - 1, lb + 1, lb + p2);a[rt].r = build(p1 + 1, ra, lb + p2 + 1, rb);return rt;}void bfs(int x){queue<int>q;queue<int>v;q.push(x);while (!q.empty()){int w = q.front();q.pop();//if (w == 0)// break;v.push(w);if (a[w].r != 0)q.push(a[w].r);if (a[w].l != 0)q.push(a[w].l);}while (!v.empty()){cout << v.front();v.pop();}return;}int main1(){int n;cin >> n;for (int i = 0; i < n; i++) cin >> mid[i];for (int i = 0; i < n; i++) cin >> fr[i];int root = build(0, n - 1, 0, n - 1);bfs(root);system("pause");return 0;}# include <stack>void test() {stack<int> s;priority_queue<int> q;for (int i = 1; i < 10; i++)s.push(i);for(int i = 1; i < 10; ++i)cout << s.top() << endl;q.push(1);cout << q.top() << endl;q.pop();cout << q.empty();}int main() {test();system("pause");return 0;}