Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- int n, m, tek_znach = 0;
- cin >> n;
- int *tree = new int[n];
- for (int i = 0; i < n; i++)
- cin >> tree[i];
- cin >> m;
- tek_znach = 0;
- string *word = new string[m];
- for (int i = 0; i<m; i++)
- cin >> word[i];
- if (tree[0] != -1)
- cout << tree[0] << endl;
- else cout << "empty" << endl;
- for (int i = 0; i < m; i++)
- if (word[i] == "left" && tek_znach*2+1 < n && tree[tek_znach*2+1] != -1)
- {
- tek_znach = tek_znach*2+1;
- cout << tree[tek_znach] << endl;
- }
- else if (word[i] == "left" && tek_znach*2+1 >= n)
- {
- cout << "empty" << endl;
- tek_znach = n;
- }
- else if (word[i] == "left" && tree[tek_znach*2+1] == -1)
- {
- tek_znach = tek_znach*2+1;
- cout << "empty" << endl;
- }
- else if (word[i] == "right" && tek_znach*2+2 < n && tree[tek_znach*2+2] != -1)
- {
- tek_znach = tek_znach*2+2;
- cout << tree[tek_znach] << endl;
- }
- else if (word[i] == "right" && tek_znach*2+2 >= n)
- {
- cout << "empty" << endl;
- tek_znach = n;
- }
- else if (word[i] == "right" && tree[tek_znach*2+2] == -1)
- {
- tek_znach = tek_znach*2+2;
- cout << "empty" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement