int main(){ int i; /*Declare an integer n and assign it a value of 20.*/ int n = 20; /*Allocate memory for an array of n integers using malloc.*/ int *numbers = malloc(n * sizeof(int)); /*Fill this array with random numbers, using rand().*/ initializeSeed(); for(i =0; i < n; i ++){ numbers[i] = randomNumber(100);/*Will return a number from 0 to 99*/ } /*Print the contents of the array.*/ for(i = 0; i < n; i ++){ printf("Contents of array[%d]: %d\n", i, numbers[i]); } /*Pass this array along with n to the sort() function of part a.*/ sort(numbers,n); /*Print the contents of the array.*/ for(i = 0; i < n; i ++){ printf("Contents of sorted array[%d]: %d\n", i, numbers[i]); } return 0; }
BOOLEAN randomSchreier( PermGroup *const G, RandomSchreierOptions rOptions) { Unsigned noOfOriginalGens, successCount, level, finalLevel, nonInvolRejectCount, levelLowestOrder; unsigned long curOrder, lowestOrder; Permutation **originalGen; FactoredInt trueGroupOrder, factoredOrbLen; Permutation *gen; Permutation *randGen = newIdentityPerm( G->degree), *h = newUndefinedPerm( G->degree), *lowestOrderH = newUndefinedPerm( G->degree), *tempPerm; /* Set defaults for options. */ if ( rOptions.initialSeed == 0 ) rOptions.initialSeed = 47; if ( rOptions.minWordLengthIncrement == UNKNOWN ) rOptions.minWordLengthIncrement = 7; if ( rOptions.maxWordLengthIncrement == UNKNOWN ) rOptions.maxWordLengthIncrement = 23; if ( rOptions.stopAfter == UNKNOWN ) if ( G->order ) rOptions.stopAfter = 10000; else rOptions.stopAfter = 40; if ( rOptions.reduceGenOrder == UNKNOWN ) rOptions.reduceGenOrder = TRUE; if ( rOptions.rejectNonInvols == UNKNOWN ) rOptions.rejectNonInvols = 0; if ( rOptions.rejectHighOrder == UNKNOWN ) rOptions.rejectHighOrder = 0; if ( rOptions.onlyEssentialInitGens == UNKNOWN ) rOptions.onlyEssentialInitGens = FALSE; if ( rOptions.onlyEssentialAddedGens == UNKNOWN ) rOptions.onlyEssentialAddedGens = TRUE; /* Initialize seed. */ initializeSeed( rOptions.initialSeed); /* Check that fields of G that must be null initially actually are. Then allocate these fields. */ if ( G->base || G->basicOrbLen || G->basicOrbit || G->schreierVec ) ERROR( "randschr", "A group field that must be null initially was " "nonnull.") G->base = allocIntArrayBaseSize(); G->basicOrbLen = allocIntArrayBaseSize(); G->basicOrbit = (UnsignedS **) allocPtrArrayBaseSize(); G->schreierVec = (Permutation ***) allocPtrArrayBaseSize(); /* If the true group order is known, set trueGroupOrder to it. Otherwise allocate G->order and mark trueGroupOrder as undefined (i.e., noOfFactors == UNKNOWN). Then set G->order to 1. */ if ( G->order ) trueGroupOrder = *G->order; else { G->order = allocFactoredInt(); trueGroupOrder.noOfFactors = UNKNOWN; } G->order->noOfFactors = 0; /* Delete identity generators from G if present. Return immediately if G is the identity group. */ removeIdentityGens( G); if ( !G->generator) { /* Should we allocate G->base, etc??? */ G->baseSize = 0; return TRUE; } /* Adjoin an inverse image array to each permutation if absent. */ adjoinGenInverses( G); /* Choose an initial segment of the base so that each generator moves some base point. */ initializeBase( G); /* Here we allocate and construct an array of pointers to the original generators. */ noOfOriginalGens = 0; originalGen = allocPtrArrayDegree(); for ( gen = G->generator ; gen ; gen = gen->next ) originalGen[++noOfOriginalGens] = gen; /* Fill in the level of each generator, and make each generator essential at its level and above. (????) */ for ( gen = G->generator ; gen ; gen = gen->next ) { gen->level = levelIn( G, gen); MAKE_NOT_ESSENTIAL_ALL( gen); for ( level = 1 ; level <= gen->level ; ++level ) MAKE_ESSENTIAL_AT_LEVEL( gen, level); } /* Construct the orbit length, basic orbit, and Schreier vector arrays. Set G->order (previously allocated) to the product of the basic orbit lengths. */ G->order->noOfFactors = 0; for ( level = 1 ; level <= G->baseSize ; ++level ) { G->basicOrbLen[level] = 1; G->basicOrbit[level] = allocIntArrayDegree(); G->schreierVec[level] = allocPtrArrayDegree(); if ( rOptions.onlyEssentialInitGens ) constructBasicOrbit( G, level, "FindEssential"); else constructBasicOrbit( G, level, "AllGensAtLevel" ); } /* The variable successCount will count the number of consecutive times the quasi-random group element can be factored successfully. */ successCount = 0; nonInvolRejectCount = 0; while ( successCount < rOptions.stopAfter && (trueGroupOrder.noOfFactors == UNKNOWN || !factEqual( G->order, &trueGroupOrder)) ) { randomizeGen( noOfOriginalGens, originalGen, rOptions.minWordLengthIncrement, rOptions.maxWordLengthIncrement, randGen); if ( factorGroupElt( G, randGen, h, &finalLevel) ) ++successCount; else { successCount = 0; if ( rOptions.reduceGenOrder ) replaceByPower( G, finalLevel, h); if ( nonInvolRejectCount >= rOptions.rejectNonInvols || isInvolution( h) ) { if ( nonInvolRejectCount > 0 && (lowestOrder < (curOrder = permOrder(h)) || lowestOrder == curOrder && levelLowestOrder > finalLevel) ) { tempPerm = h; h = lowestOrderH; lowestOrderH = tempPerm; finalLevel = levelLowestOrder; } if ( finalLevel == G->baseSize+1 ) { if ( G->baseSize >= options.maxBaseSize ) ERROR1i( "initializeBase", "Base size exceeded maximum of ", options.maxBaseSize, ". Rerun with -mb option.") G->base[++G->baseSize] = pointMovedBy( h); G->basicOrbLen[G->baseSize] = 1; G->basicOrbit[G->baseSize] = allocIntArrayDegree(); G->schreierVec[G->baseSize] = allocPtrArrayDegree(); } assignGenName( G, h); addStrongGenerator( G, h, FALSE); h = newUndefinedPerm( G->degree); nonInvolRejectCount = 0; } else { curOrder = permOrder( h); if ( curOrder == 0 ) curOrder = ULONG_MAX; if ( nonInvolRejectCount == 0 || curOrder < lowestOrder || (curOrder == lowestOrder && finalLevel > levelLowestOrder) ) { copyPermutation( h, lowestOrderH); lowestOrder = curOrder; levelLowestOrder = finalLevel; } ++nonInvolRejectCount; } } } freePtrArrayDegree( originalGen); deletePermutation( randGen); deletePermutation( h); deletePermutation( lowestOrderH); return trueGroupOrder.noOfFactors != UNKNOWN && factEqual( G->order, &trueGroupOrder); }