#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
struct Node{
Node* l;
Node* r;
char ch;
Node (Node* l = NULL, Node* r = NULL):l(l), r(r){}
};
void build (string a, string &b, Node Point, int la){
if (a.size() == 1) {
Node point = new Node;
if (la == 1) Point.l = &point;
else Point.r = &point;
point.l = NULL;
point.r = NULL;
return;
}
Node point = new Node;
point.ch = a[0];
if (la == 1) Point.l = &point;
else Point.r = &point;
string c;
string d;
string e;
cout << "B: " << b << endl << "A: " << a << endl;
for (int i = 0; i < b.find(a[0]); i++)
c[i] = a[i];
int o = 0;
for (int i = b.find(a[0]); i < b.size(); i++)
d[o++] = a[i];
for (int i = 0; i < b.size() - 1; i++)
e[i] = b[i + 1];
build(c, e, Point, 1);
build(d, e, Point, -1);
}
void print (Node root){
if (root.l != NULL || root.r != NULL) {
print(root.l);
print(root.r);
}
cout << root.ch;
return;
}
int main(){
string a, b;
while (cin >> a >> b){
Node root;
root.ch = a[0];
string c;
string d;
string e;
for (int i = 0; i < b.find(a[0]); i++)
c[i] = a[i];
int o = 0;
for (int i = b.find(a[0]); i < b.size(); i++)
d[o++] = a[i];
//下面是比较字符串的第一位和字符串的输出
cout << "D[0]: " << d[0] << endl;
cout << "D: " << d << endl;
//(结果前面的可以输出,后面的不行)
for (int i = 0; i < b.size() - 1; i++)
e[i] = b[i + 1];
// cout << "C:" << d << endl << "E:" << e << endl;
return 0;
build(c, e, root, 1);
build(d, e, root, -1);
print(root);
}
return 0;
}
为什么其中的字符串无法输出?
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
struct Node{
Node* l;
Node* r;
char ch;
Node (Node* l = NULL, Node* r = NULL):l(l), r(r){}
};
void build (string a, string &b, Node Point, int la){
if (a.size() == 1) {
Node point = new Node;
if (la == 1) Point.l = &point;
else Point.r = &point;
point.l = NULL;
point.r = NULL;
return;
}
Node point = new Node;
point.ch = a[0];
if (la == 1) Point.l = &point;
else Point.r = &point;
string c;
string d;
string e;
cout << "B: " << b << endl << "A: " << a << endl;
for (int i = 0; i < b.find(a[0]); i++)
c[i] = a[i];
int o = 0;
for (int i = b.find(a[0]); i < b.size(); i++)
d[o++] = a[i];
for (int i = 0; i < b.size() - 1; i++)
e[i] = b[i + 1];
build(c, e, Point, 1);
build(d, e, Point, -1);
}
void print (Node root){
if (root.l != NULL || root.r != NULL) {
print(root.l);
print(root.r);
}
cout << root.ch;
return;
}
int main(){
string a, b;
while (cin >> a >> b){
Node root;
root.ch = a[0];
string c;
string d;
string e;
for (int i = 0; i < b.find(a[0]); i++)
c[i] = a[i];
int o = 0;
for (int i = b.find(a[0]); i < b.size(); i++)
d[o++] = a[i];
//下面是比较字符串的第一位和字符串的输出
cout << "D[0]: " << d[0] << endl;
cout << "D: " << d << endl;
//(结果前面的可以输出,后面的不行)
for (int i = 0; i < b.size() - 1; i++)
e[i] = b[i + 1];
// cout << "C:" << d << endl << "E:" << e << endl;
return 0;
build(c, e, root, 1);
build(d, e, root, -1);
print(root);
}
return 0;
}
为什么其中的字符串无法输出?