九度 二叉排序树
題目鏈接 :?點擊打開鏈接
答案:
#include <bits/stdc++.h>
#define MAX 100<<2+10
int bt[MAX];
int Insert_Tree(int pos,int v){
? ? if (bt[pos] == 0){
? ? ? ? bt[pos] = v;
? ? ? ? if (pos != 1)
? ? ? ? ? ? return bt[pos/2];
? ? ? ? else
? ? ? ? ? ? return -1;
? ? ? ? }else{
? ? ? ? ?if (v>bt[pos]){
? ? ? ? ? ? Insert_Tree(pos*2+1 , v);
? ? ? ? ?}else{
? ? ? ? ? ? ?Insert_Tree(pos*2 , v);
? ? ? ? ?}
? ? ? ? }
}
int main(){
?int n ;
?while (~scanf("%d",&n)){
? ? ? ? memset(bt,0,sizeof(bt));
? ? for(int i = 1 ; i <= n ; i++){
? ? ? ? ? ? int a ;
? ? ? ? scanf("%d",&a);
? ? ? ? printf("%d\n",Insert_Tree(1,a));
? ? }
?}
?return 0;
}
總結
- 上一篇: 菜鸟Linux系列:[4]SSH免密码登
- 下一篇: 汇编语言中的常数