#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iostream>
//---------------------------------------------------------------------------
#define max_value 100
using namespace std;
void init_Random()
{
srand(time(NULL));
}
typedef struct temporary_next
{
temporary_next *next;
int value_str;
}position;
bool 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;
}
int *first_digit_Array;
class list_Direction
{
private:
typedef struct
{
position *start;
position *end;
}show;
show info_show;
public:
list_Direction()
{
info_show.start=info_show.end=NULL;
}
void plus_next(int value)
{
position *new_pos;
new_pos=new position;
new_pos->value_str=value;
new_pos->next=NULL;
if(info_show.start==NULL)
info_show.start=info_show.end=new_pos;
else
{
(info_show.end)->next=new_pos;
info_show.end=new_pos;
}
}
list_Direction& operator --()
{
if(info_show.start==info_show.end)
{
delete info_show.start;
info_show.start=info_show.end=NULL;
}
else
{
position *temp_position=info_show.start;
while((temp_position->next)!=info_show.end)
info_show.end=temp_position;
delete temp_position->next;
temp_position->next=NULL;
}
return (*this);
}
list_Direction friend& operator +(list_Direction &A, list_Direction &B)
{
list_Direction *temp_List=new list_Direction;
position *C=(A.info_show).start;
position *D=(B.info_show).start;
do
{
temp_List->plus_next(C->value_str);
C=C->next;
}while(C!=NULL);
do
{
temp_List->plus_next(D->value_str);
D=D->next;
}while(D!=NULL);
return (*temp_List);
}
bool is_Empty()
{
if(info_show.start==NULL)
return true;
else
return false;
}
void write_Elements()
{
position *temp_pos=info_show.start;
while(temp_pos!=NULL)
{
printf("%d ",temp_pos->value_str);
temp_pos=temp_pos->next;
printf("\n");
}
printf("\n");
}
~list_Direction()
{
while(!is_Empty())
(*this)--;
;
}
};
int main(int argc, char* argv[])
{
first_digit_Array=new int[max_value];
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
first_digit_Array[i]=j;
++i;
}
++j;
}while(i<max_value);
list_Direction X,Y,Z;
for(i=0;i<max_value;i++)
{
X.plus_next(first_digit_Array[rand()%max_value]);
Y.plus_next(first_digit_Array[rand()%max_value]);
}
Z=X+Y;
Z.write_Elements();
delete first_digit_Array;
getch();
return 0;
}
Brak komentarzy:
Prześlij komentarz