I am having a problem on how to optimize this numbering algorithm, can you advise me

#include
#include
#include
#include
using namespace std;
struct Node
{
string a, b, res;
};

string maxNumber2(string a, string b)
{
Node root;
root.a = a;
root.b = b;
root.res = string("");
stack Stack;
Stack.push(root);
vector bag;
Node t;
Node newNode_1, newNode_2;
set S;
while (!Stack.empty())
{
Node temp = Stack.top();
Stack.pop();
if ((temp.a.size() == 0) && (temp.b.size() == 0))
S.insert(temp.res);
if (temp.a.size() > 0)
{
newNode_1.b = temp.b;
newNode_1.res = temp.res + temp.a[0];
if (temp.a.size() == 1)
newNode_1.a = "";
else
{
newNode_1.a = string(&temp.a[1]);
}
Stack.push(newNode_1);
}
if (temp.b.size() > 0)
{
newNode_2.a = temp.a;
newNode_2.res = temp.res + temp.b[0];
if (temp.b.size() == 1)
newNode_2.b = "";
else
newNode_2.b = string(&temp.b[1]);
Stack.push(newNode_2);
}
}
set::iterator it = S.end();
--it;
return ((*S.end()).c_str(), (*it).c_str());
}

Comments (1)