My file where is my structure - date.h
#include <stdio.h>
struct Base
{
struct Base *left;
struct Base *right;
System::Int32 value;
};
and main program:
#pragma endregion
int *first_Value;
System::Void init_Random()
{
srand(time(NULL));
}
System::Boolean is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
System::Void itemsAdd(struct Base *base)
{
if(base!=NULL)
{
itemsAdd(base->left);
listBox1->Items->Add(base->value.ToString());
itemsAdd(base->right);
}
}
struct Base *my_Tree(struct Base *base, int my_value)
{
int temp;
temp=sizeof(struct Base);
if(base==NULL)
{
base=(struct Base*) malloc(temp);
base->value=my_value;
base->left=NULL;
base->right=NULL;
}
else
if(base->value>my_value)
base->left=my_Tree(base->left,my_value);
else
base->right=my_Tree(base->right,my_value);
return (base);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
init_Random();
first_Value=new int[1000];
int i,j;
i=0;
j=1;
do
{
if(is_First(j))
{
first_Value[i]=j;
i++;
j++;
}
else
j++;
}while(i<1000);
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
delete first_Value;
Close();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
int random_value,i;
struct Base *down;
down=NULL;
for(i=0;i<4;i++)
{
random_value=rand()%1000;
down=(struct Base*) my_Tree(down,first_Value[random_value]);
itemsAdd(down);
}
}
};
}
Brak komentarzy:
Prześlij komentarz