Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

2K_programuvanna / 07_12_1

.CPP
Скачиваний:
29
Добавлен:
19.04.2015
Размер:
748 б
Скачать
#include <stdio.h>
#include <stdlib.h>
 struct Node{
   int d;
   Node *left, *right;
 };
 Node *root=NULL;
 void add (int x);
 int printtree (Node *root);
 int main () {
   int i,x,k;
   scanf("%d",&k);
   for(i=0;i<k;i++){
     scanf("%d",x);
   }
   for(i=0;i<k;i++){
     add(x);
   return 0;
   printtree (10);
 }

void add(int x){
 Node *t, *cur, *next;
 t=(Node*)malloc(sizeof(Node));
 t->d=x;
 t->left=t->right=NULL;
 if(root=NULL){
  root=t;
  return ;
 }
 next=root;
 while(next!=NULL)(
   cur=next;
   if(cur->d>x) {next=cur->left;}
   else {next=cur->right;}
 }
 if(cur->d>x) {cur->left=t;}
 else {cur->right=t;}
}

int printtree (Node *root) {
 Node *cur=root;
 if (cur!=NULL) return root;

Соседние файлы в папке 2K_programuvanna