示例#1
0
void ssort(struct TablaMerge arr, struct TablaMerge arrAux, int lo, int hi)
{
    if(lo >= hi) return;
    int mid = (lo + hi)/2;
    ssort(arr, arrAux, lo, mid);
    ssort(arr, arrAux, mid+1, hi);
    mmerge(arr, arrAux, lo, mid, hi);
}
示例#2
0
int
main(int argc, char *argv[])
{
  int i, j;
  int testvector[IVEC_LEN];
  int sresvector[IVEC_LEN];

  printf("1..1\n");
  for (j = 2; j < IVEC_LEN; j++) {
    /* Populate test vectors */
    for (i = 0; i < j; i++)
      testvector[i] = sresvector[i] = initvector[i];

    /* Sort using qsort(3) */
    qsort(testvector, j, sizeof(testvector[0]), sorthelp);
    /* Sort using reference slow sorting routine */
    ssort(sresvector, j);

    /* Compare results */
    for (i = 0; i < j; i++)
      assert(testvector[i] == sresvector[i]);
  }

  printf("ok 1 - qsort\n");

  return(0);
}
示例#3
0
文件: sorttest.c 项目: mwmaher/sort.c
/****************************************************************************
   function: test_1
 parameters:
    returns: if successful
	       TRUE
	     else
	       FALSE
    purpose: Test the selection sort ssort() function by sorting an array
	     of integers();
****************************************************************************/
char test_1(FILE *output)
  {
  time_t start,
	 finish;
  char status = PASS;
  int i,
      j,
      int_array[TESTARRAYSIZE];

  /* load array in ascending order */
  for (i = 0; i < TESTARRAYSIZE; i++)
    int_array[i] = i;

  /* sort with selection sort function in descending order */
  time(&start);
  ssort(int_array, TESTARRAYSIZE, sizeof(int), comp_desc_int);
  time(&finish);
  fprintf(output, "\nsort time: %f ", difftime(finish, start)/1000);
  /* check array for descending order */
  for (i = 0, j = TESTARRAYSIZE - 1; i < TESTARRAYSIZE; i++, j--)
    {
    if (int_array[i] != j)
      {
      status = FAIL;
      break;
      }
    }
  if (status == FAIL)
    fprintf(output, "\nERROR: Unexpected array element (%.0d, %.0d)\n", i, j);
  return(status);
  }
int main( int argc, char *argv[] )
{
    int         i, j;
    int         d[N];
    
    //srand
    srand((unsigned) time(NULL));
    
    // set data
    for (i = 0; i < N; i++ )
        d[i] = rand() % 10;
    
    // show
/*
    printf("     ");
    for (i = 0; i < N; i++)
        printf("%2d", i);
    printf("\n");
*/
    
    show_data(d, N);
    
    ssort(d, N);

    show_data(d, N);
    
    return 0;
}//int main( int argc, char *argv[] )
示例#5
0
void shellsort(int a[], int size){
	int d[] = {1, 3, 5};

	for(int i=2; i>-1; --i){
		ssort(a, size, d[i]);
	}
}
示例#6
0
static int ptfs_init( const char * path ) {
	DIR * rdiffdir;
	struct dirent * ent;
	mounttime = time(0);
	root_atime = mounttime;
	
	sprintf( rdiffpath, "%s/rdiff-backup-data/", path ); /* strlen("katalog=") == 8 */
	if ( ( rdiffdir = opendir( rdiffpath ) ) == NULL ) {
		fprintf( stderr, "BLAD: Brak dostepu do %s!\n", rdiffpath );
		return 1; 
	}

	while ( ( ent = readdir( rdiffdir ) ) != NULL )
		if ( !strncmp( ent->d_name, "mirror_metadata.", 16 ) )
			if ( metadata( ent->d_name ) ) return 1;

/* To sortowanie jest tylko na wszelki wypadek, gdyby sie okazalo, 
 ze sesje zostaly wczytane w nieodpowiedniej kolejnosci */
	ssort( sessions, sessCounter ); 

	if ( sessCounter == 0 ) {
		fprintf( stderr, "BLAD: katalog rdiff-backup-data nie ma zapisnej zadnej sesji!\n" );
		return 1;
	}
	
	strncpy( link_current + strlen(link_current), sessions[sessCounter-1].nm + 1, BUFLEN - strlen(link_current) );
	link_curr_atime = sessions[sessCounter-1].st.time;
	if ( sessCounter > 1 ) {
		strncpy( link_previous + strlen(link_previous), sessions[sessCounter-2].nm + 1, BUFLEN - strlen(link_previous) );
		link_prev_atime = sessions[sessCounter-2].st.time;
	}

	return 0;
}
示例#7
0
文件: Deletion.cpp 项目: NixonZ/Cpp-Z
void deletion(int A[],int ele, int &T)
{
    int pos;
    ssort(A,T);
    pos=bsearch(A,ele,T);
    for(int i=pos;i<T-1;i++)
    {
        A[i]=A[i+1];
    }
    T--;
}
示例#8
0
文件: dsl4.c 项目: agentzz9/algomny
int main()
{
	int arr[5];
	
	printf("Enter 5 elements(for selection sort):\n");
	input(arr);
	ssort(arr);
	printf("\nSorted:\n");
	output(arr);printf("\n\n");
    system("pause");
	return 0;
}
示例#9
0
int main()
{
int arr[10],m;
do
{
cout<<"enter no of elements to be sorted:";
cin>>m;
}while(m>10);
input(arr,m);
ssort(arr,m);
cout<<"sorted elements are:"<<endl;
display(arr,m);
getch();
return 0;
}  
示例#10
0
void main()
{
 clrscr();
 float A[25],n;
 do
 {
   cout<<"Enter the no. of elements less than 25"<<endl;
     cin>>n;
 }while(n>25);
 input(A,n);
 display(A,n);
 ssort(A,n);
 bsearch(A,n);
 getch();
}
示例#11
0
void test(void) {
	int *a = NULL, *t = NULL, *b;
	int n = 0, i = 0, j = 0;
	for (i = 0; i < 1000; ++i) {
		n = rand() % 100;
		a = (int *)malloc(sizeof(int) * n);
		t = (int *)malloc(sizeof(int) * n);
		b = (int *)malloc(sizeof(int) * n);
		for (j = 0; j < n; ++j) {
			a[j] = rand() % 20;
			b[j] = a[j];
		}
		ssort(a, n);
		qsort(b, n, sizeof(int), cmp);
		for (j = 0; j < n; ++j) {
			if (a[j] != b[j]) printf("Error\n");
		}
		free(a); free(b); free(t);
	}
}
示例#12
0
文件: 06-06.c 项目: hzd02765/meikai
int main(void)
{
  int i;
  int x[7];
  int nx = sizeof(x) / sizeof(x[0]);

  printf("%d個の整数を入力せよ。\n", nx);
  for(i = 0; i < nx; i++){
    printf("x[%d] : ", i);
    scanf("%d", &x[i]);
  }

  ssort(x, nx);

  puts("昇順にソートしました。");
  for(i = 0; i < nx; i++){
    printf("x[%d] = %d\n", i, x[i]);
  }

  return (0);
}
示例#13
0
ATF_TC_BODY(qsort_test, tc)
{
	int testvector[IVEC_LEN];
	int sresvector[IVEC_LEN];
	int i, j;

	for (j = 2; j < IVEC_LEN; j++) {
		/* Populate test vectors */
		for (i = 0; i < j; i++)
			testvector[i] = sresvector[i] = initvector[i];

		/* Sort using qsort(3) */
		qsort(testvector, j, sizeof(testvector[0]), sorthelp);
		/* Sort using reference slow sorting routine */
		ssort(sresvector, j);

		/* Compare results */
		for (i = 0; i < j; i++)
			ATF_CHECK_MSG(testvector[i] == sresvector[i],
			    "item at index %d didn't match: %d != %d",
			    i, testvector[i], sresvector[i]);
	}
}
示例#14
0
int main(int argc, char* argv[]) {

	if (argc < 2) {
		PrintUsage();
		exit(1);
	}
	int argi = 1;
	string saFile = argv[argi++];
	vector<string> inFiles;
	
	int doBLT = 1;
	int bltPrefixLength = 8;
	int parsingOptions = 0;
	SAType saBuildType = larsson;
	int read4BitCompressed  = 0;
	int diffCoverSize = 0;
	while (argi < argc) {
		if (strlen(argv[argi]) > 0 and
				argv[argi][0] == '-'){ 
			parsingOptions = 1;
		}
		if (!parsingOptions) {
			inFiles.push_back(argv[argi]);
		}
		else {
			if (strcmp(argv[argi], "-blt") == 0) {
				doBLT = 1;
        if (argi < argc - 1) {
          bltPrefixLength = atoi(argv[++argi]);
          if (bltPrefixLength == 0) {
            cout << argv[argi] << " is not a valid lookup table length." << endl;
            exit(1);
          }
        }
        else {
          cout << "Please specify a lookup table length." << endl;
          exit(1);
        }
			}
			else if (strcmp(argv[argi], "-mamy") == 0) {
				saBuildType = manmy;
			}
			else if (strcmp(argv[argi], "-larsson") == 0) {
				saBuildType = larsson;
			}
			else if (strcmp(argv[argi], "-mcilroy") == 0) {
				saBuildType = mcilroy;
			}
			else if (strcmp(argv[argi], "-slow") == 0) {
				saBuildType = slow;
			}
			else if (strcmp(argv[argi], "-kark") == 0) {
				saBuildType = kark;
			}
			else if (strcmp(argv[argi], "-mafe") == 0) {
				saBuildType = mafe;
			}
			else if (strcmp(argv[argi], "-welter") == 0) {
				saBuildType = welter;
			}
			else if (strcmp(argv[argi], "-welterweight") == 0) {
        if (argi < argc-1) {
          diffCoverSize = atoi(argv[++argi]);
        }
        else {
          cout << "Please specify a difference cover size.  Valid values are 7,32,64,111, and 2281.  Larger values use less memory but may be slower." << endl;
          exit(1);
        }
        if ( ! (diffCoverSize == 7 or 
                diffCoverSize == 32 or
                diffCoverSize == 64 or 
                diffCoverSize == 111 or
                diffCoverSize == 2281) ) {
          cout << "The difference cover size must be one of 7,32,64,111, or 2281." << endl;
          cout << "Larger numbers use less space but are more slow." << endl;
          exit(1);
        }
			}
			else if (strcmp(argv[argi], "-4bit") == 0) {
				read4BitCompressed = 1;
			}
			else {
				PrintUsage();
				cout << "ERROR, bad option: " << argv[argi] << endl;
				exit(1);
			}
		}
		++argi;
	}
  
  if (inFiles.size() == 0) {
    //
    // Special use case: the input file is a fasta file.  Write to that file + .sa
    //
    inFiles.push_back(saFile);
    saFile = saFile + ".sa";
  }
  
	VectorIndex inFileIndex;
	FASTASequence seq;
	CompressedSequence<FASTASequence> compSeq;

	if (read4BitCompressed == 0) {
		for (inFileIndex = 0; inFileIndex < inFiles.size(); ++inFileIndex) {
			FASTAReader reader;
			reader.Init(inFiles[inFileIndex]);
			reader.SetSpacePadding(111);
			if (saBuildType == kark) {
				//
				// The Karkkainen sa building method requires a little extra
				// space at the end of the dna sequence so that counting may
				// be done mod 3 without adding extra logic for boundaries.
				//
			}
  
			if (inFileIndex == 0) {
				reader.ReadAllSequencesIntoOne(seq);
				reader.Close();
			}
			else {
				while(reader.ConcatenateNext(seq)) {
					cout << "added " << seq.title << endl;
				}
			}
		}
		seq.ToThreeBit();
		//seq.ToUpper();
	}
	else {
		assert(inFiles.size() == 1);
		cout << "reading compressed sequence." << endl;
		compSeq.Read(inFiles[0]);
		seq.seq = compSeq.seq;
		seq.length = compSeq.length;
		compSeq.RemoveCompressionCounts();
		cout << "done." << endl;
	}

  //
  // For now, do not allow creation of suffix arrays on sequences > 4G.
  //
  if (seq.length >= UINT_MAX) {
    cout << "ERROR, references greater than " << UINT_MAX << " bases are not supported." << endl;
    cout << "Consider breaking the reference into multiple files, running alignment. " << endl;
    cout << "against each file, and merging the result." << endl;
    exit(1);
  }
	vector<int> alphabet;
	
	SuffixArray<Nucleotide, vector<int> >  sa;
	//	sa.InitTwoBitDNAAlphabet(alphabet);
	//	sa.InitAsciiCharDNAAlphabet(alphabet);
  sa.InitThreeBitDNAAlphabet(alphabet);

	if (saBuildType == manmy) {
		sa.MMBuildSuffixArray(seq.seq, seq.length, alphabet);
	}
	else if (saBuildType == mcilroy) {
		sa.index = new SAIndex[seq.length+1];
		DNALength i;
		for (i = 0; i < seq.length; i++) { sa.index[i] = seq.seq[i] + 1;}
		sa.index[seq.length] = 0;
		ssort(sa.index, NULL);
		for (i = 1; i < seq.length+1; i++ ){ sa.index[i-1] = sa.index[i];};
		sa.length = seq.length;
	}
	else if (saBuildType == larsson) {
		sa.LarssonBuildSuffixArray(seq.seq, seq.length, alphabet);
	}
	else if (saBuildType == kark) {
		sa.index = new SAIndex[seq.length];
		seq.ToThreeBit();
		DNALength p;
		for (p = 0; p < seq.length; p++ ){ seq.seq[p]++; }
		KarkkainenBuildSuffixArray<Nucleotide>(seq.seq, sa.index, seq.length, 5);
		sa.length = seq.length;
	}
	else if (saBuildType == mafe) {
		//		sa.MaFeBuildSuffixArray(seq.seq, seq.length);
		
	}
	else if (saBuildType == welter) {
		if (diffCoverSize == 0) {
			sa.LightweightBuildSuffixArray(seq.seq, seq.length);
		}
		else {
			sa.LightweightBuildSuffixArray(seq.seq, seq.length, diffCoverSize);
		}
	}
	if (doBLT) {
		sa.BuildLookupTable(seq.seq, seq.length, bltPrefixLength);
	}
	sa.Write(saFile);

	return 0;

}
示例#15
0
void tester(int start, int end, int step) {

    FILE *f = fopen("tempi.csv", "w+");

    struct timeval start1, end1;
    struct timeval start2, end2;
    struct timeval start3, end3;

    double tot1, tot2, tot3;

    int a1[end];
    int a2[end];
    int a3[end];

    for (; start <= end; start += step) {
        printf("testo con %d\n", start);

        fillRandomArray(a1, start, start / 5);
        copyArray(a1, a2, start);
        copyArray(a1, a3, start);

        gettimeofday(&start1, NULL);
        ssort(a1, start);
        gettimeofday(&end1, NULL);
        tot1 = (end1.tv_sec - start1.tv_sec) * 1000.0; // sec to ms
        tot1 += (end1.tv_usec - start1.tv_usec) / 1000.0; // us to ms


        gettimeofday(&start2, NULL);
        ssort2(a2, start);
        gettimeofday(&end2, NULL);
        tot2 = (end2.tv_sec - start2.tv_sec) * 1000.0; // sec to ms
        tot2 += (end2.tv_usec - start2.tv_usec) / 1000.0; // us to ms

        gettimeofday(&start3, NULL);
        isort(a3, start);
        gettimeofday(&end3, NULL);
        tot2 = (end3.tv_sec - start3.tv_sec) * 1000.0; // sec to ms
        tot2 += (end3.tv_usec - start3.tv_usec) / 1000.0; // us to ms

        printf("tempo selection = %.4f \ntempo selectionMax = %.4f \ntempo insertion = %f\n", tot1, tot2, tot3);


        if (sorted(a1, start))
            printf("a e' ordinato\n");
        else
            printf("a non e' oridinato\n");

        if (sorted(a2, start))
            printf("b e' ordinato\n");
        else
            printf("b non e' oridinato\n");

        if (sorted(a3, start))
            printf("c e' ordinato\n");
        else
            printf("c non e' oridinato\n");

        fprintf(f, "%d,%5.4f,%5.4f,%5.4f\n", start, tot3, tot1, tot2);
        /*
        fprintf(f, "----Tempo di esecuzione degli algoritmi di ordinamento con %d elementi----\n\n", start);
        fprintf(f, "Insertion Sort                                        --> : \t%5.4f secondi\n", tot3);
        fprintf(f, "Selection Sort con estrazioni successive del minimo   --> : \t%5.4f secondi\n", tot1);
        fprintf(f, "Selection Sort con estrazioni successive del massimo  --> : \t%5.4f secondi\n\n\n", tot2);
         */
    }

    fclose(f);
}