Pagini recente » Cod sursa (job #2136547) | Cod sursa (job #1638575) | Cod sursa (job #1122596) | Cod sursa (job #2371153) | Cod sursa (job #964997)
Cod sursa(job #964997)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
struct node
{
int value;
node* left;
node* right;
};
void update( node*& root, int val )
{
if ( !root )
{
root = new node;
root->value = val;
return;
}
if ( val <= root->value )
update( root->left, val );
if ( val > root->value )
update( root->right, val );
}
void print( node *root )
{
if ( root->left )
print( root->left );
g << root->value << " ";
if ( root->right )
print( root->right );
}
int main()
{
node *R = NULL;
int n, a;
f >> n;
for ( int i = 0; i < n; i++ )
{
f >> a;
update(R, a);
}
print(R);
}