예제 #1
0
int* _quick_sort(int arr[], int left, int right) {
    if (right <= left) {
        return arr;
    }
    int p = partition(arr, left, right);
    _quick_sort(arr, left, p-1);
    _quick_sort(arr, p+1, right);
    return arr;
}
예제 #2
0
void _quick_sort(int* nums, int left, int right) {
    if (left >= right) {
        return;
    }

    int p = _partition(nums, left, right);

    _quick_sort(nums, 0, p-1);
    _quick_sort(nums, p+1, right);
}
예제 #3
0
파일: quick_sort.c 프로젝트: xxha/ds_algos
void _quick_sort(int array[], int start, int end)  
{  
	int middle;  
	if(start >= end)  
		return;  
  
	middle = get_middle(array, start, end);  
	_quick_sort(array, start, middle -1);  
	_quick_sort(array, middle + 1, end);  
}  
void _quick_sort(T* buff, size_t n)
{
	if (2 > n)
		return;

	/*optional questionable optimization (?) to call insert sort on small portions
	if (10 > n)
	{
		_insert_sort(buff, n);
		return;
	}
	*/

	// generate pivot point
	// unstable because with simplest approach of getting a median number when we devide sum of numbers by count of numbers
	// the sum of numbers can overflow over the limit of type
	// will use it for now
	// besides for out purposes it's not absolutely critical to get presise median since the array is presumed unsorted anyway
	// so it's unlikely that the median number will actually be median for all values in the array
	T pivot = (buff[0] + buff[n - 1] + buff[n / 2] + buff[n / 4] + buff[(n / 4) * 3]) / 5;
	T temp = 0;

	size_t curr = 0, nextbig = n - 1, smalls = 0, bigs = 0;
	while (curr <= nextbig)
	{
		if (pivot < buff[curr])
		{
			temp = buff[nextbig];
			buff[nextbig] = buff[curr];
			buff[curr] = temp;

			bigs++;
			if (0 == nextbig)
				break;
			nextbig--;

		}
		else if (buff[curr] < pivot)
		{
			temp = buff[smalls];
			buff[smalls] = buff[curr];
			buff[curr] = temp;
			smalls++;
			curr++;
		}
		else
			curr++;
	}

	_quick_sort(buff, smalls);
	_quick_sort(buff + (n - bigs) , bigs);
}
예제 #5
0
파일: quick_sort.c 프로젝트: phoxis/codez
/* Quick sort recursive function */
static void _quick_sort (void *base, int lo, int high, size_t size, int (*compar)(const void *, const void *))
{
  int piv_index;

  if (lo >= high)
  {
    return;
  }

  piv_index = partition_array (base, lo, high, size, compar);
  _quick_sort (base, lo, piv_index - 1, size, compar);
  _quick_sort (base, piv_index + 1, high, size, compar);

  return;  
}
예제 #6
0
파일: quick_sort.c 프로젝트: xxha/ds_algos
void quick_sort(int array[], int length)  
{  
	int median = 0;  
	if(NULL == array || 0 == length)  
		return;  
  
	_quick_sort(array, 0, length -1);  
}  
T* quick_sort(T* buff, size_t n)
{
	if (!buff || 2 > n)
		return 0;
	std::cout << std::endl << "quick_sort" << std::endl;
	YouLong startT = ::GetTickCount();

	_quick_sort(buff, n);

	outputElapsed(::GetTickCount() - startT);
	return buff;
}
예제 #8
0
int quick_sort(int *array, int low, int high)
{
    int p;

    if (low < high)
    {
        p = _quick_sort(array, low, high);

        quick_sort(array, low, p-1);
        quick_sort(array, p+1, high);
    }

    return 0;
}
예제 #9
0
파일: main.c 프로젝트: jack2949/sheduled
static void _quick_sort(int head, int end, TASK_ENTRY *task)
{
    int first, last;
	TASK_ENTRY tmp;
    if(NULL == task || head >= end)
        return ;

    first = head;
    last = end;
    tmp = task[head];
    while (head < end)
    {
        /* The "=" is must, or loop lock */
        while(head < end && task[end].startTime >= tmp.startTime) end --;
        task[head] = task[end];
        /* The "=" is must. */
        while(head < end && task[head].startTime <= tmp.startTime) head ++;
        task[end] = task[head];
    }
    task[head] = tmp;

    _quick_sort(first, head - 1, task);
    _quick_sort(head + 1, last, task);
}
예제 #10
0
파일: kruskal.c 프로젝트: Vilain-Velu/FINAL
/* tri rapide sur une liste chainée - choix du pivot naïf */
Arbre* _quick_sort (Arbre* L1, Arbre* end)
{
    Arbre *pivot, *tmp, *next, *prec, *suiv;
    if ( L1!= end && L1->Suivant != end )
    {
        /* partitionnement (fin liste 'prec' : 'pivot'; fin liste 'suiv' : 'end') */
        pivot = L1, prec = pivot, suiv = end;
        for ( tmp=L1->Suivant; tmp != end; tmp=next )
        {
            next = tmp->Suivant;
            if (tmp->dist > pivot->dist)
               { tmp->Suivant = suiv; suiv = tmp; }/* ajoute la cellule a la liste 'suiv' */
            else
               { tmp->Suivant = prec; prec = tmp; }/* ajoute la cellule a la liste 'prec' */
        }
        /* appels recursifs */
        prec = _quick_sort (prec, pivot);
        suiv = _quick_sort (suiv, end);
        /* recolle la liste */
        pivot->Suivant = suiv;
        return prec;
    }
    return L1;
}
예제 #11
0
void quick_sort(int* nums, int n) {
    _quick_sort(nums, 0, n-1);
}
예제 #12
0
int* quick_sort(int arr[], int len) {
    return _quick_sort(arr, 0, len -1);
}
예제 #13
0
파일: main.c 프로젝트: jack2949/sheduled
static int _load_config()
{
	cJSON *config = NULL;
	cJSON *data = NULL;
	cJSON *elm = NULL;
	cJSON *startTime = NULL;
	cJSON *command = NULL;
	int cnt = 0;
	int index = 0;
	int hour,min,second;
	int ret = OK;
	
	if (NULL != task)
	{
		free(task);
		task = NULL;
	}

	config = _get_JSON_from_file(CONFIG_FILE_PATH);
	if (NULL == config)
	{
		LOG_ERR("get config errer");
		ret = ERROR;
		goto leave;
	}

	/* attendtion free */
	PRINTF("data = %s", cJSON_Print(config));	
	data = cJSON_GetObjectItem(config, "data");
	cnt = cJSON_GetArraySize(data);

	task = (TASK_ENTRY *)malloc(sizeof(TASK_ENTRY)*cnt);
	if (NULL == task)
	{
		LOG_ERR("malloc error!");
		ret = ERROR;
		goto leave;
	}
	
	for(index = 0; index < cnt; index++)
	{
		elm = cJSON_GetArrayItem(data, index);
		startTime = cJSON_GetObjectItem(elm, "startTime");
		if( startTime != NULL && startTime->type == cJSON_String )
		{
			sscanf(startTime->valuestring, "%d:%d:%d", &hour, &min, &second);
			task[index].startTime = hour * 60 * 60 + min * 60 + second;
		}
		
		command = cJSON_GetObjectItem(elm, "command");
		if( command != NULL && command->type == cJSON_String )
		{
			if(strlen(command->valuestring) < MAX_COMMAND_LENGTH)
			{
				strcpy(task[index].command, command->valuestring);
			}
			else
			{
				LOG_ERR("command %s size %d error!", command->valuestring, strlen(command->valuestring));
				_log_to_file(ERROR_LOG_FILE_PATH, "command %s size %d error!",	command->valuestring, strlen(command->valuestring));
			}
		}
	}

	_quick_sort(0, cnt - 1, task);
	task_index = 0;
	task_MAX = cnt;
	
#ifdef LOG_DEBUG
	for(index = 0; index < cnt; index++)
	{
		PRINTF("%02d:%02d:%02d	%s", task[index].startTime/3600, (task[index].startTime % 3600)/60, task[index].startTime%60, task[index].command);
	}
#endif

leave:
	if(config)
		cJSON_Delete(config);
	
	return ret;
}
예제 #14
0
파일: quick_sort.c 프로젝트: phoxis/codez
/* Quick sort function to call from outside */
void quick_sort (void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
{
  _quick_sort (base, 0, nmemb - 1, size, compar);

  return;
}
예제 #15
0
파일: kruskal.c 프로젝트: Vilain-Velu/FINAL
Arbre* quick_sort (Arbre* list)
{
    return _quick_sort (list, NULL);
}