Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #define MAXINT 32000
- #define BASE 10
- void printvek(int * vek, int n )
- { int i;
- for(i=0; i<n; i++ )
- printf("%i ", vek[i]);
- printf("\n");
- }
- int * genvek(int n, int x, int lim)
- { int i;
- int * vek = (int*)malloc( sizeof(int) * n );
- if (x == 1)
- {for( i=0; i<=n; i++)
- vek[i] = i+1;
- }
- else
- if (x == 2)
- {srand( (unsigned)time(NULL) );
- for( i=0 ; i<n ; i++ )
- vek[i] = rand() % lim + 1;
- }
- else
- if (x == 3)
- {for( i=0; i<n; i++)
- vek[i] = n - i;
- }
- return vek;
- }
- struct node {
- int val;
- struct node * left;
- struct node * right;
- };
- void wrb( struct node * rad , int * vect )
- {
- static int count = 0;
- if( rad->left ) wrb( rad->left , vect );
- vect[count++] = rad->val;
- //prn( vect , 20 );
- //printf("(%i):%i\n",count,rad->val);
- //count++;
- if( rad->right ) wrb( rad->right , vect );
- }
- void binary_search_tree( int * vect , int size )
- { struct node * rad,* nou,* p;
- int i;
- rad = (struct node *)malloc( sizeof(struct node) );
- rad->val = vect[0];
- rad->left = rad->right = NULL;
- for( i=1 ; i<size ; i++ )
- {
- nou = (struct node *)malloc( sizeof(struct node) );
- nou->val = vect[i];
- nou->left = nou->right = NULL;
- p = rad;
- while(1)
- {
- if( p->val > nou->val )
- if( p->left ) p=p->left;
- else {
- p->left = nou;
- break;
- }
- else
- if( p->right ) p=p->right;
- else {
- p->right = nou;
- break;
- }
- }
- }
- //bin(rad,0);
- //wrb( rad , vect );
- //printf("\n");
- printvek( vect , size );
- }
- void radix_sort( int * vect , int size )
- {
- int * temp,step=1,nr_dig[BASE],pos[BASE],i,max=vect[0],start;
- temp = (int*)malloc( size * sizeof(int) );
- for( i=1 ; i<size ; i++ )
- if( max < vect[i] ) max = vect[i];
- while( max > 0 )
- {
- for( i=0 ; i<BASE ; i++ ) nr_dig[i]=0;
- for( i=0 ; i<size ; i++ )
- nr_dig[ (vect[i] / step) % BASE ]++;
- for( i=1 ; i<BASE ; i++ )
- nr_dig[i] += nr_dig[i-1];
- pos[0]=0;
- for( i=0 ; i<BASE-1 ; i++ )
- pos[i+1] = nr_dig[i];
- for( i=0 ; i<size ; i++ )
- {
- start = (vect[i] / step) % BASE;
- temp[ pos[start]++ ] = vect[i];
- }
- for( i=0 ; i<size ; i++ )
- vect[i] = temp[i] ;
- max = max / BASE;
- step = step * BASE;
- //prn( nr_dig , BASE );
- printvek(vect,size);
- }
- }
- void cocktail_sort( int * vect , int size )
- {
- int swap = 1,i,temp;
- while( swap )
- {
- swap = 0;
- for( i=0 ; i<size-1 ; i++ )
- if( vect[i] > vect[i+1] )
- {
- temp = vect[i];
- vect[i] = vect[i+1];
- vect[i+1] = temp;
- swap = 1;
- }
- if( !swap ) break;
- //swap=0;
- for( i=size-2 ; i>=0 ; i-- )
- if( vect[i] > vect[i+1] )
- {
- temp = vect[i];
- vect[i] = vect[i+1];
- vect[i+1] = temp;
- swap = 1;
- }
- }
- }
- int main()
- {
- int choice;
- int * v1;
- printf("Mod Choice:\n");
- printf("1)Modul de testare:\n2)Modul de analiza:\n");
- scanf("%d",&choice);
- v1 = genvek(10, 2, 100);
- //clrscr();
- if( choice == 1 )
- {
- printf("Modul analiza -|--\n");
- printvek(v1, 10);
- }
- else
- {
- printf("Modul testare :)\n");
- printvek(v1, 10);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement