Mai intai trebuie sa te autentifici.
Cod sursa(job #2002264)
Utilizator | Data | 19 iulie 2017 11:18:05 | |
---|---|---|---|
Problema | Sortare prin comparare | Scor | 40 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 1.22 kb |
#include <stdio.h>
#include <malloc.h>
#define FIN "algsort.in"
#define FOUT "algsort.out"
#define SIZE 500005
typedef struct node {
int info;
struct node *left;
struct node *right;
} Node;
int arr[ SIZE ],
n;
void insert_binary_tree(Node **root, int val) {
if((*root) == NULL) {
(*root) = (Node*)malloc(sizeof(Node));
(*root)->info = val;
(*root)->left = NULL;
(*root)->right = NULL;
} else {
if((*root)->info > val) {
insert_binary_tree(&((*root)->left), val);
} else {
insert_binary_tree(&((*root)->right), val);
}
}
};
void inorder(Node *node) {
if(node->left) inorder(node->left);
printf("%d ", node->info);
if(node->right) inorder(node->right);
};
int main() {
int i, //this var is an iterator
elem; //this var is an element of the array
Node *root = NULL;
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
scanf("%d", &n);
for(i = 0; i < n; i++) scanf("%d", &elem), insert_binary_tree(&root, elem);
inorder( root );
return(0);
};