fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5.  
  6. struct node{
  7. int data;
  8. node* right;
  9. node* left;
  10. };
  11.  
  12. node* makeroot(node* root, int u)
  13. {
  14. // root = new node;
  15. root->data = u;
  16. root->right = NULL;
  17. root->left = NULL;
  18. return root;
  19. }
  20.  
  21. void insert(node* root, int u, int v, char c)
  22. {
  23. if(root == NULL)
  24. {
  25. root = new node;
  26. root = makeroot(root, u);
  27. }
  28. if(c == 'L')
  29. {
  30. root->left = new node;
  31. root->left = makeroot(root, v);
  32. }
  33. else
  34. {
  35. root->right = new node;
  36. root->right = makeroot(root, v);
  37. }
  38. }
  39.  
  40. void leverOrder(node* root)
  41. {
  42. cout << root->data << " ";
  43. leverOrder(root->left);
  44. leverOrder(root->right);
  45. }
  46.  
  47. int main()
  48. {
  49. int t; cin >> t;
  50. while(t--)
  51. {
  52. int n; cin >> n;
  53. node* root = NULL;
  54. for(int i = 1; i <= n; i++)
  55. {
  56. int x, y;
  57. char c;
  58. cin >> x >> y >> c;
  59. insert(root, x, y, c);
  60. }
  61. leverOrder(root);
  62. }
  63. }
  64.  
Runtime error #stdin #stdout 0.01s 5396KB
stdin
Standard input is empty
stdout
Standard output is empty