文章
85
粉丝
0
获赞
579
访问
14.6k
#include <bits/stdc++.h>
using namespace std;
typedef struct Node {
int data;
struct Node* left;struct Node* right;
struct Node* parent;
}*STree;
void buildSTree(STree &root,int data,STree parent) {
if (root==NULL) {
root =new Node;
root->data = data;
root->left = NULL;
root->right = NULL;
root->parent = parent;
if (root->parent==NULL) {
cout <<-1<<endl;
}
else {
cout <<root->parent->data<<endl;
}
return;
}
if (data==root->data) {
return;
}
if (data<root->data) {
buildSTree(root->left,data,root);
}
if (data>root->data) {
buildSTree(root->right,data,root);
}
}
int main() {
int n;
while (cin>>n) {
vector<int> v;
for (int i=0;i<n;i++) {
int data;
...
登录后发布评论
暂无评论,来抢沙发