Pagini recente » Cod sursa (job #2470439) | Cod sursa (job #1505425) | Cod sursa (job #2121565) | Cod sursa (job #881636) | Cod sursa (job #965001)
Cod sursa(job #965001)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int a[500005];
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;
f >> n;
for ( int i = 0; i < n; i++ )
f >> a[i];
random_shuffle ( a, a + n );
for ( int i = 0; i < n; i++ )
update(R,a[i]);
print(R);
}