//排序比较法
bool contain2(char * stra,char * strb){
  char tmpA[100];
  char tmpB[100];
  /*	use quickSort
		sprintf(tmpA,"%s",stra);
		sprintf(tmpB,"%s",strb);
		quickSort(tmpA,0,strlen(tmpA) - 1);
		quickSort(tmpB,0,strlen(tmpB) - 1);
		*/
  countSort(stra,tmpA);
  countSort(strb,tmpB);
  //printf("After sort:\n%s\n%s\n",tmpA,tmpB);
  int lena = strlen(tmpA);
  int lenb = strlen(tmpB);
  int i,j;
  for(i = 0,j = 0;j < lena && i < lenb;j++){
	if(tmpA[j] == tmpB[i]){
	  i++;
	}else if(tmpA[j] > tmpB[i]){
	  return false;
	}
  }
  if(i == lenb){
	return true;
  }else{
	return false;
  }
}
示例#2
0
int main() {
    int test1[] = {2, 6, 4, 3, 2, 3, 4, 6, 3, 4, 3, 5, 2, 6};
    int size1 = 14;

    countSort(test1, size1);
    return 1;
}
示例#3
0
// Driver program to test above function
void _counting_sort()
{
    char str[] = "geeksforgeeks";//"applepp";

    countSort(str);

    printf("Sorted string is %s\n", str);
}
示例#4
0
文件: rSort.c 项目: zaid09/algorithms
void radixsort(int arr[], int n)
{
    int exp;
    int m = getMax(arr, n);
 
    for (exp = 1; m/exp > 0; exp *= 10)
        countSort(arr, n, exp);
}
示例#5
0
int radixSort(int a[], int size){

    int m= findMax (a,size);
    int exp;
    for(exp = 1;m/exp>0;exp = exp*10){
        countSort(a,size,exp);
    }
}
示例#6
0
void radixSort::sortRadix(int size)
{
	int max = radixSort::getMax(size);

	for (int i = 1; max / i > 0; i *= 10)
	{
		countSort(size, i);
	}
}
示例#7
0
// The main function to that sorts arr[] of size n using Radix Sort
void radixsort(int arr[], int n) {
    // Find the maximum number to know number of digits
    int m = getMax(arr, n);

    // Do counting sort for every digit. Note that instead of passing digit
    // number, exp is passed. exp is 10^i where i is current digit number
    for (int exp = 1; m/exp > 0; exp *= 10)
        countSort(arr, n, exp);
}
示例#8
0
// Driver program to test above function
int main()
{
    char str[] = "geeksforgeeks";//"applepp";
 
    countSort(str);
 
    printf("Sorted string is %s\n", str);
    return 0;
}
void radixSort(int v[], int N)
{
    int m = getMax(v, N);
    
    for(int exp = 1; m/exp>0; exp*=10)
    {
        countSort(v, N, exp);
    }
}
示例#10
0
文件: sorting_test.cpp 项目: xeta/XXV
TEST(Sorting, CountSort) {
	int size = _1000;
	int* array = craeteRandomArray(size);
	BM.start();
	countSort(array, size, size);
	cout << "[ TIME     ] 100000 => " << BM.getTime() << endl;
	EXPECT_TRUE(isSorted(array, size));
	free(array);
}
示例#11
0
int main()
{
    int arr[ARRSIZE] = {0};
    init_arr(arr, ARRSIZE);
    printf("before sort:\n");
    output_arr(arr, ARRSIZE);
    countSort(arr, ARRSIZE);
    printf("after sort:\n");
    output_arr(arr, ARRSIZE);
    return 0;
}
示例#12
0
void radixSort(int array[],int n)
{	int temp=1;
	int max=findMax(array,n);

	while(max/temp>0)
	{	
		countSort(array,n,temp);
		temp*=10;
	}

}
示例#13
0
int main()
{
	int i, arr[10000]
	for(i=0;i<10000;i++){
		arr[i] = rand()%1000000;
	}

	countSort(str);

	printf("Sorted string is %s\n", str);
	return 0;
}
int main(int argc, char** argv) {
	bsp_init(countSort, argc, argv);
	
	srand(time(NULL));
	
	sscanf(argv[1],"%d",&p);
	sscanf(argv[2],"%d",&n);

	countSort();
	
	exit(0);
}
示例#15
0
文件: main.cpp 项目: vlakuc/algo
int main(int argc, char** argv) {
    // int a, b;
    // std::cin >> a >> b;
    // std::cout << a+b << std::endl;
    // std::cout << fib(10);
    // fib2();
    //fibLastDig();
    //std::cin >> n;
    // fibLastDig(atoi(argv[1]));
    countSort();


}
示例#16
0
int main()
{
	int a[]={1,3,2,4,5,2,9,8,7};
	int i = 0;
	int len = sizeof(a)/sizeof(a[0]);

	countSort(a,len);
	for(i=0;i<len;++i){
		printf("%d ",a[i]);
	}

	return 0;
}
示例#17
0
    /*
    According to: https://leetcode.com/discuss/51129/10-lines-76ms-easy-c-solution-updated-function-signature
    Write a count sort method and use it to sort the string.
    */
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        map<string, vector<string>> dict;
        for(auto str: strs){
            string sorted_str = countSort(str);
            dict[sorted_str].push_back(str);
        }

        vector<vector<string>> groups;
        for(auto group: dict){
            vector<string> g(group.second.begin(), group.second.end());
            groups.push_back(g);
        }
        return groups;
    }
示例#18
0
int* array_merge(int num_arrays, int* sizes, int** values){
  int* sumArr = (int*)calloc(sumArraySizes(num_arrays,sizes),sizeof(int));
  int i;
  int j;
  int k = 0;
  for(i=0;i<num_arrays;i++){
    for(j=0;j<sizes[i];j++){
      sumArr[k]= values[i][j];
      k++;
    }
  }
  int* sorted = countSort(k,sumArr);
  free(sumArr);
  return sorted;
}
int main(void) {
  struct CElem m[MAX], saveM[MAX];
  unsigned loopInd;
  for (loopInd = 1; loopInd <= TEST_LOOP_CNT; loopInd++) {
    printf("\n<<<<< Тест %u >>>>>\n", loopInd);
    init(m,MAX);
    memcpy(saveM, m, sizeof(m)); /* Запазва се копие на масива */
    printf("Масивът преди сортирането:\n");
    print(m,MAX);
    countSort(m,MAX);
    printf("Масивът след сортирането:\n");
    print(m,MAX);
    check(m,saveM,MAX);
  }
  return 0;
}
int main(void) {
  unsigned m[MAX], saveM[MAX];
  unsigned loopInd;
  printf("start -- \n");
  for (loopInd = 1; loopInd <= TEST_LOOP_CNT; loopInd++) {
    init(m,MAX);
    memcpy(saveM, m, sizeof(m)); /* Запазва се копие на масива */
    printf("Масивът преди сортирането:\n");
    print(m,MAX);
    countSort(m,MAX);
    printf("Масивът след сортирането:\n");
    print(m,MAX);
    check(m,saveM,MAX);
  }
  return 0;
}
void radixSort(int arr[], int n) {
	int maxx = *max_element(arr, arr+n);

	for (int mul = 1; maxx/mul > 0; mul *= 10)
		countSort(arr, n, mul);
}
void radixSort(int* A, int size, int d) {
	for (int i = 1; i <= d; ++i) {
		countSort(A, size, 9, i);		
	}
}