Example #1
0
int main()
{
  FILE *cinfile ;
  char buf[MAX_BUF_LEN] ;

  cinfile = fopen(PHONE_CIN_FILE, "r") ;
  if( !cinfile ) {
    printf("Error opening the file %s\n", PHONE_CIN_FILE) ;
    return 1 ;
  }

  do {
    fgets(buf, MAX_BUF_LEN, cinfile) ;
  } while( strncmp(buf, CHARDEF_BEGIN, strlen(CHARDEF_BEGIN)) ) ;

  for(;;) {
    fgets(buf, MAX_BUF_LEN, cinfile) ;
    if(buf[0] == '%') break ;
    if( DoWord(buf) == DO_WORD_ERROR) {
      printf("%s file error!\n", PHONE_CIN_FILE) ;
      return 1 ;
    }
  }
  fclose(cinfile) ;

  if( strncmp( buf, CHARDEF_END, strlen(CHARDEF_END))) {
    printf("The end of the file %s is error!\n", PHONE_CIN_FILE) ;
    return 1 ;
  }

  CountSort() ;
  Output() ;

  return 0 ;
}
Example #2
0
void RadixSort(char* input[], int num, int list)
{
    for( int i = 2 ; i >= 0; i-- ){
        if ( CountSort(input, num, i) == false )
            return;
    }
}
Example #3
0
void TestCountSort()
{
	int array[] = {2,5,6,9,1,3,4,7,0,8};
	CountSort(array,sizeof(array)/sizeof(array[0]));
	for(int i = 0; i<sizeof(array)/sizeof(array[0]); i++)
	{
		cout<<array[i] <<" " ;
	}
	cout <<endl;
}
Example #4
0
double czasWykonaniaSortowania(int tab[], int iloscElementow, int zakresOd, int zakresDo, int Niter)
{
	int* tabout = (int*)malloc(sizeof(int) * iloscElementow);
	errorcheck(tabout == NULL, "Brak pamieci!");

	double time = clock();
	for (int i = 0; i < Niter; i++)
	{
		CountSort(tab, tabout, iloscElementow, zakresOd, zakresDo);
	}
	time = (clock() - time) / CLOCKS_PER_SEC;

	free(tabout);
	return time;
}
Example #5
0
int main()
{
	clock_t start,finish;
	double duration;

	int wait;
	printf("Before Sort:");
	getRandData();
	printRandData();
	start=clock();
	CountSort(randData,RAND_NUM);
	finish=clock();
	printf("After Sort:");
	printRandData();
	duration = (double)(finish - start) / CLOCKS_PER_SEC;
	printf( "Sort Used time:%f seconds\n", duration );
	scanf("%d",&wait);
}
Example #6
0
int main(int argc, char* argv[])
{
	FILE *cinfile;
	char buf[ MAX_BUF_LEN ];
	char *phone_cin;

	if (argc < 2) {
		fprintf( stderr, "Usage: sort_word <phone.cin>\n" );
		return 1;
	}

	phone_cin = argv[1];
	cinfile = fopen( phone_cin, "r" );
	if ( ! cinfile ) {
		fprintf( stderr, "Error opening the file %s\n", phone_cin );
		return 1;
	}

	do {
		fgets( buf, MAX_BUF_LEN, cinfile );
	} while ( strncmp( buf, CHARDEF_BEGIN, strlen( CHARDEF_BEGIN ) ) );

	for ( ; ; ) {
		fgets( buf, MAX_BUF_LEN, cinfile );
		if ( buf[ 0 ] == '%' )
			break;
		if ( DoWord( buf ) == DO_WORD_ERROR ) {
			fprintf( stderr, "The file %s is corrupted!\n", phone_cin );
			return 1;
		}
	}
	fclose( cinfile );

	if ( strncmp( buf, CHARDEF_END, strlen( CHARDEF_END ) ) ) {
		fprintf( stderr, "The end of the file %s is error!\n", phone_cin );
		return 1;
	}

	CountSort();
	Output();

	return 0;
}