12

Gooooogle  •  5个月前


#include <iostream>
#include<string>
using namespace std;
string str;

typedef struct node {
	string data;
	node* left;
	node* right;
}*tree;

void create(tree& T) {
	T = new node;
	string x; 
	cin >> x;
	if (x[0] == '-' && x[1]=='1') {
		T = NULL;
		return;
	}
	T->data = x;
	create(T->left);
	create(T->right);
}

void solve(tree T,string str) {
	if (T == NULL) {
		return;
	}
	string temp = T->data;

	if (T->left == NULL && T->right == NULL) {
		str = str + temp;
		cout << str<<endl;
	}
	else {
		str = str + temp+"->";
	}
	solve(T->left,str);
	//cout << T->data << "->";
	solve(T->right,str);
}

int main() {
	tree T;
	create(T);
	solve(T,str);
	return 0;
}

评论:

你好


柯陵  •  5个月前

请先登录,才能进行评论