#include <bits/stdc++.h>
using
namespace
std;
struct
Node {
int
data;
struct
Node *left, *right;
};
int
myCompare(string X, string Y)
{
string XY = X.append(Y);
string YX = Y.append(X);
return
XY.compare(YX) > 0 ? 1 : 0;
}
void
printLargest(vector<string> arr)
{
sort(arr.begin(), arr.end(), myCompare);
for
(
int
i = 0; i < arr.size(); i++)
cout << arr[i];
cout <<
"\n"
;
}
int
maxLevelNumber(
struct
Node* root)
{
if
(root == NULL)
return
0;
int
result = root->data;
queue<Node*> q;
q.push(root);
while
(!q.empty()) {
int
count = q.size();
vector<string> v;
while
(count--) {
Node* temp = q.front();
q.pop();
v.push_back(to_string(temp->data));
if
(temp->left != NULL)
q.push(temp->left);
if
(temp->right != NULL)
q.push(temp->right);
}
printLargest(v);
}
return
result;
}
struct
Node* newNode(
int
data)
{
struct
Node* node =
new
Node;
node->data = data;
node->left = node->right = NULL;
return
(node);
}
int
main()
{
struct
Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
root->right->right = newNode(8);
root->right->right->left = newNode(6);
root->right->right->right = newNode(7);
maxLevelNumber(root);
return
0;
}