• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ sorter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中sorter函数的典型用法代码示例。如果您正苦于以下问题:C++ sorter函数的具体用法?C++ sorter怎么用?C++ sorter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sorter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sorter

/**
 * Sort an (ascending) array of integers
 *
 * Arguments:
 * arr    The array to search
 * length Number of elements in the array
 *
 * Uses "quicksort" to sort "arr".  Use the first element of the array
 * as the pivot.  
 *
 * Your solution MUST use recursive function (or functions)
 * 
 * quicksort works in the following way: 
 * 
 * find an element in the array (this element is called the
 * pivot). 
 *
 * rearrange the array's elements into two parts: the part smaller
 * than this pivot and the part greater than this pivot; make the pivot
 * the element between these two parts
 * 
 * sort the first and the second parts separately by repeating the 
 * procedure described above
 * 
 * You will receive no point if you use any other sorting algorithm.
 * You cannot use selection sort, merge sort, or bubble sort.
 * 
 * Some students are fascinated by the name of bubble sort.  In
 * reality, bubble sort is rarely used because it is slow.  It is a
 * mystery why some students (or even professors) like bubble sort.
 * Other than the funny name, bubble sort has nothing special and is
 * inefficient, in both asymptotic complexity and the amount of data
 * movement.  There are many algorithms much better than bubble sort.
 * You would not lose anything if you do not know (or forget) bubble
 * sort.
 *
 */
void sorter(int *arr, int length, int *start, int size)
{
  int pivot = *start, *copy, count, curr, decr = 0, incr = 0;
  copy = malloc(sizeof(int)*size);
  for(count = 0; count < size; count++)
    {
      curr = *(start+count);
      if(curr > pivot)
        {
          *(copy+ size - 1 + decr) = curr;
          decr--;
        }
      if(curr < pivot)
        {
          *(copy+incr) = curr;
          incr++;
        }
    }
  for(count = 0; count < size - (incr-decr); count++)
    *(copy+incr+count) = pivot;
  for(count = 0; count < size; count++)
    *(start+count)=*(copy+count);
  free(copy);
  if(incr>1)
    sorter(arr, length, start, incr);
  if(decr<-1)
    sorter(arr, length, (start+size+decr), -decr);
  
}
开发者ID:gweaver0,项目名称:ece264,代码行数:66,代码来源:answer03.c


示例2: sorter

/**
 * calls sorter for subArrays of current subArray of input array and merge sorted subArrays
 * @param array - array with data
 * @param p - start of subArray
 * @param r - end of subArray
 */
void sorter(int *array, const int p, const int r) {
    int q = (p+r)/2;
    if(p < q) {
        sorter(array, p, q);
    }
    if(q+1 < r) {
        sorter(array, q+1, r);
    }
    merger(array, p ,r);
}
开发者ID:KOlexandr,项目名称:AlgorithmsII.Scala,代码行数:16,代码来源:BitonicSort.cpp


示例3: line

AirspaceIntersectionVector
AirspaceCircle::Intersects(const GeoPoint &start, const GeoPoint &end,
                           const TaskProjection &projection) const
{
  const fixed f_radius = projection.ProjectRangeFloat(m_center, m_radius);
  const FlatPoint f_center = projection.ProjectFloat(m_center);
  const FlatPoint f_start = projection.ProjectFloat(start);
  const FlatPoint f_end = projection.ProjectFloat(end);
  const FlatLine line(f_start, f_end);

  FlatPoint f_p1, f_p2;
  if (!line.intersect_circle(f_radius, f_center, f_p1, f_p2))
    return AirspaceIntersectionVector();

  const fixed mag = line.dsq();
  if (!positive(mag))
    return AirspaceIntersectionVector();

  const fixed inv_mag = fixed(1) / mag;
  const fixed t1 = FlatLine(f_start, f_p1).dot(line);
  const fixed t2 = (f_p1 == f_p2) ?
    fixed(-1) : FlatLine(f_start, f_p2).dot(line);

  const bool in_range = (t1 < mag) || (t2 < mag);
  // if at least one point is within range, capture both points

  AirspaceIntersectSort sorter(start, *this);
  if ((t1 >= fixed(0)) && in_range)
    sorter.add(t1 * inv_mag, projection.Unproject(f_p1));

  if ((t2 >= fixed(0)) && in_range)
    sorter.add(t2 * inv_mag, projection.Unproject(f_p2));

  return sorter.all();
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:35,代码来源:AirspaceCircle.cpp


示例4: TEST

TEST(int_merge_sorter_test, test_six_element_array)
{
    std::vector<int> example = {7,2,5,3,6,1};
    IntMergeSorter sorter(example);
    sorter.sort();
    EXPECT_EQ("[1,2,3,5,6,7]", to_string(example));
}
开发者ID:chenyibin,项目名称:CppAlgorithms,代码行数:7,代码来源:int_merge_sorter_test.cpp


示例5: deselectAll

void QTodoList::sort()
{
	QTodoSortDialog sort_dialog;

	deselectAll();

	if(sort_dialog.exec() == QDialog::Accepted)
	{
		preserveContentsYPos();
		const QTodoSortCriteriaMap* criterias = sort_dialog.getCriterias();

		QPtrList<QWidget> list_widgets;
		list_widgets.append(0);
		QTodoListIterator it(this);
		for(;it.current();++it)
			list_widgets.append(it.current());

		QTodoListItemsSorter sorter(&list_widgets,criterias);
		QPtrList<QWidget>* sorted = sorter.get();

		QTUM::get()->startRecording();
		takeAll();
		for(unsigned int i = 0; i < sorted->count(); ++i)
		{
			if(QTodoItem* item = dynamic_cast<QTodoItem*>(sorted->at(i)))
			{
				insertTodo(item,i);
				item->setDepth(item->getDepth());
			}
		}
		QTUM::get()->stopRecording();
		restoreContentsYPos();
	}
}
开发者ID:tobimensch,项目名称:qtodo,代码行数:34,代码来源:qtodo_list.cpp


示例6: inferSchema

    ArrayDesc inferSchema(std::vector< ArrayDesc> schemas, std::shared_ptr< Query> query)
	{
        //As far as chunk sizes, they can be a pain! So we allow the user to specify an optional chunk size
        //as part of the sort op.

        assert(schemas.size() >= 1);
        ArrayDesc const& schema = schemas[0];
        size_t chunkSize = 0;
        for (size_t i =0; i<_parameters.size(); i++)
        {
            if(_parameters[i]->getParamType()==PARAM_LOGICAL_EXPRESSION)
            {
                chunkSize = evaluate(((std::shared_ptr<OperatorParamLogicalExpression>&)_parameters[i])->getExpression(),
                                     query, TID_INT64).getInt64();
                if(chunkSize <= 0)
                {
                    throw SYSTEM_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_CHUNK_SIZE_MUST_BE_POSITIVE);
                }
                break;
            }
        }

        // Use a SortArray object to build the schema.
        // Note: even though PhysicalSort::execute() uses an expanded schema, with chunk_pos and cell_pos,
        //       these additional attributes are projected off before returning the final sort result.
        const bool preservePositions = false;
        SortArray sorter(schema, arena::getArena(), preservePositions, chunkSize);

        return sorter.getOutputArrayDesc();
	}
开发者ID:suhailrehman,项目名称:scidb,代码行数:30,代码来源:LogicalSort.cpp


示例7: command

int command(const char *cmd) {
	if (strncasecmp(cmd,"pen",3)==0) pens(cmd);
	else if (strncasecmp(cmd,"dot",3)==0) pens(cmd);
	//else if (strncasecmp(cmd,"act",3)==0) action_link(cmd);
	else if (strncasecmp(cmd,"act",3)==0) action(cmd);
	else if (strncasecmp(cmd,"cust",4)==0) pens(cmd);
	else if (strncasecmp(cmd,"sort",4)==0) sorter(cmd);
	else if (strncasecmp(cmd,"prev",4)==0) move(cmd);
	else if (strncasecmp(cmd,"next",4)==0) move(cmd);
	else if (strncasecmp(cmd,"redr",4)==0) draw(None);
	else if (strncasecmp(cmd,"mute",4)==0) mute(cmd);
	else if (strncasecmp(cmd,"quit",4)==0) running = False;
	else if (strncasecmp(cmd,"full",4)==0) toggle_fullscreen();
	else if (strncasecmp(cmd,"zoom",4)==0) {
		char *c;
		if ( (c=strchr(cmd, ' ')) ) {
			while (c && *c == ' ') c++;
			if (*c == '\0') return 1;
			if (*c == 'q') {
				if (!(c=strchr(c, ' '))) return 1;
				while (c && *c == ' ') c++;
				if (*c == '\0') return 1;
				else if (*c == '1') zoom_rect(0, 0, show->w/2, show->h/2);
				else if (*c == '2') zoom_rect(show->w/2, 0, show->w, show->h/2);
				else if (*c == '3') zoom_rect(0, show->h/2, show->w/2, show->h);
				else if (*c == '4') zoom_rect(show->w/2, show->h/2, show->w, show->h);
				else return 1;
			}
			else pens(cmd);
		}
		else return 1;
	}
	XSync(dpy, True);
	return 0;
}
开发者ID:thamnos,项目名称:Slider,代码行数:35,代码来源:actions.c


示例8: shellSort

void shellSort(Iterator begin, Iterator end, Sequence strideSeq, Predicate pred)
{
    struct RecursiveSorter
    {
        RecursiveSorter(Iterator begin, Iterator end, Sequence strideSeq, Predicate pred):
            beg_(begin), end_(end), strideSeq_(strideSeq), pred_(pred), numElems_(std::distance(beg_, end_)) {}

        void sort(uint index)
        {
            if(strideSeq_(index + 1) < numElems_)
                sort(index + 1);

            detail::hSort(beg_, end_, strideSeq_(index), pred_);
        }

    private:
        Iterator beg_, end_;
        Sequence strideSeq_;
        Predicate pred_;
        uint numElems_;
    };

    RecursiveSorter sorter(begin, end, strideSeq, pred);
    sorter.sort(0);
}
开发者ID:CCJY,项目名称:coliru,代码行数:25,代码来源:main.cpp


示例9: main

int main(int argc, char* argv[])
{
	global_program_name.setValue2( argv[0] );
	sorted_arguments = (InputArgument**) malloc( argc * sizeof(InputArgument*) );

	try
	{
		for ( int index = 0; index < argc; ++index )
			all_arguments.push_back( new InputArgument(index, argv[index]) );

		assert(argc >= 2);
		InputArgument input_count(1, argv[1]);
		read_arguments( input_count.valueToUll() );

		std::thread printer1( print_arguments_1, 0 );
		std::thread sorter( sort_arguments );

		printer1.join();
		sorter.join();
		std::thread printer2( print_arguments_2 );

		printer2.join();
		delete_arguments();

		return 0;
	}
	catch(std::exception& exc)
	{
		std::cerr << "Exception: " << exc.what() << std::endl;
		return 1;
	}
}
开发者ID:citic,项目名称:botNeumann,代码行数:32,代码来源:alli.cpp


示例10: sort

    void sort(Master&                   master,               //!< master object
              const Assigner&           assigner,             //!< assigner object
              std::vector<T> Block::*   values,               //!< all values to sort
              std::vector<T> Block::*   samples,              //!< (output) boundaries of blocks
              size_t                    num_samples,          //!< desired number of samples
              const Cmp&                cmp,                  //!< comparison function
              int                       k   = 2,              //!< k-ary reduction will be used
              bool                      samples_only = false) //!< false: results will be all_to_all exchanged; true: only sort but don't exchange results
    {
        bool immediate = master.immediate();
        master.set_immediate(false);

        // NB: although sorter will go out of scope, its member functions sample()
        //     and exchange() will return functors whose copies get saved inside reduce
        detail::SampleSort<Block,T,Cmp> sorter(values, samples, cmp, num_samples);

        // swap-reduce to all-gather samples
        RegularDecomposer<DiscreteBounds> decomposer(1, interval(0,assigner.nblocks()), assigner.nblocks());
        RegularSwapPartners   partners(decomposer, k);
        reduce(master, assigner, partners, sorter.sample(), detail::SkipIntermediate(partners.rounds()));

        // all_to_all to exchange the values
        if (!samples_only)
            all_to_all(master, assigner, sorter.exchange(), k);

        master.set_immediate(immediate);
    }
开发者ID:ColorVertexSampleOrganization,项目名称:VTK,代码行数:27,代码来源:algorithms.hpp


示例11: sortParallel

/**
 * calls bitonicSort for array with data and use it sort array
 * @param array - array with data
 */
void sortParallel(int *array, const int length) {
    #pragma omp parallel
    {
        #pragma omp single nowait
        sorter(array, 0, length-1, MIN_ELEMENTS_FOR_PARALLELISM);
    }
}
开发者ID:KOlexandr,项目名称:AlgorithmsII.Scala,代码行数:11,代码来源:BitonicSort.cpp


示例12: sorter

AirspaceIntersectionVector
AirspaceCircle::Intersects(const GeoPoint &start, const GeoPoint &end) const
{
  AirspaceIntersectSort sorter(start, end, *this);

  const fixed f_radius = m_task_projection->fproject_range(m_center, m_radius);
  const FlatPoint f_center = m_task_projection->fproject(m_center);
  const FlatPoint f_start = m_task_projection->fproject(start);
  const FlatPoint f_end = m_task_projection->fproject(end);
  const FlatLine line(f_start, f_end);

  FlatPoint f_p1, f_p2;
  if (line.intersect_circle(f_radius, f_center, f_p1, f_p2)) {
    const fixed mag = line.dsq();
    if (positive(mag)) {
      const fixed inv_mag = fixed_one / mag;
      const fixed t1 = FlatLine(f_start, f_p1).dot(line);
      const fixed t2 = (f_p1 == f_p2) ?
                       -fixed_one : FlatLine(f_start, f_p2).dot(line);

      const bool in_range = (t1 < mag) || (t2 < mag);
      // if at least one point is within range, capture both points

      if ((t1 >= fixed_zero) && in_range)
        sorter.add(t1 * inv_mag, m_task_projection->funproject(f_p1));

      if ((t2 >= fixed_zero) && in_range)
        sorter.add(t2 * inv_mag, m_task_projection->funproject(f_p2));
    }
  }

  return sorter.all();
}
开发者ID:mobotics,项目名称:XCSoar,代码行数:33,代码来源:AirspaceCircle.cpp


示例13: layoutAboutToBeChanged

QModelIndex KrVfsModel::addItem(vfile * vf)
{
    emit layoutAboutToBeChanged();

    if(lastSortOrder() == KrViewProperties::NoColumn) {
        int idx = _vfiles.count();
        _vfiles.append(vf);
        _vfileNdx[vf] = index(idx, 0);
        _nameNdx[vf->vfile_getName()] = index(idx, 0);
        emit layoutChanged();
        return index(idx, 0);
    }

    QModelIndexList oldPersistentList = persistentIndexList();

    KrSort::Sorter sorter(createSorter());

    int insertIndex = sorter.insertIndex(vf, vf == _dummyVfile, customSortData(vf));
    if (insertIndex != _vfiles.count())
        _vfiles.insert(insertIndex, vf);
    else
        _vfiles.append(vf);

    for (int i = insertIndex; i < _vfiles.count(); ++i) {
        _vfileNdx[ _vfiles[ i ] ] = index(i, 0);
        _nameNdx[ _vfiles[ i ]->vfile_getName()] = index(i, 0);
    }

    QModelIndexList newPersistentList;
    foreach(const QModelIndex &mndx, oldPersistentList) {
        int newRow = mndx.row();
        if (newRow >= insertIndex)
            newRow++;
        newPersistentList << index(newRow, mndx.column());
    }
开发者ID:KDE,项目名称:krusader,代码行数:35,代码来源:krvfsmodel.cpp


示例14: sorter

typename SortedList<T, Pred>::Node* SortedList<T, Pred>::merge_lists(typename SortedList<T, Pred>::Node* list1, unsigned length1, typename SortedList<T, Pred>::Node* list2, unsigned length2, const Sorter &sorter)
{
	unsigned i = 0, j = 0;
	SortedList<T, Pred>::Node* front = sorter(list1->Data, list2->Data) ? list1 : list2;

	// I will arbitrarily decide to just shove everything into list1.
	while (i < length1 && j < length2 && list2 != tail_)
	{
		if (sorter(list1->Data, list2->Data))
		{
			list1 = list1->Next;
			++i;
		}
		else
		{
			SortedList<T, Pred>::Node* temp = list2;
			list2 = list2->Next;
			++j;

			moveNode(temp, list1->Prev);
		}
	}

	// If there's any left over, append the rest.
	// If list1 is longer it's already in order and junk, so we
	// don't worry about it at all.
/*	while (j < length2 && list2 != tail_)
	{
		SortedList<T, Pred>::Node* temp = list2;
		list2 = list2->Next;
		++j;

		moveNode(temp, list1->Prev);
		list1 = list1->Next;
	} */
	// Aaaaaactually, all that is unnecessary.
	// In mergesort, the right block is always adjacent to the left block.
	// So, there's no point worrying about it, it's already appended for
	// your convenience.

	// The two should be stuck together now.
	// This should work because lists we're comparing should all be
	// adjacent to each other.
	return(front);
}
开发者ID:beentaken,项目名称:mmeng-personal-work,代码行数:45,代码来源:SortedList.cpp


示例15: MessageTaskDeliver

 // Serilize Constructor
 MessageTaskDeliver()
     : Message( PROTOCOL_VERSION , 131 , 0 )
 {
     task_id( "" );
     uri_list(  );
     aligner( "" );
     sorter( "" );
     reference( "" );
 }
开发者ID:Yhgenomics,项目名称:maraton-cli,代码行数:10,代码来源:MessageTaskDeliver.hpp


示例16: main

int main() {
  int shook_array[kArraySize] = {};
  RandomizeArray(shook_array, kArraySize);

  ArraySorter<int, QuickSort> sorter(shook_array, kArraySize);
  sorter.Run();
  sorter.PrintResult();

  return 0;
}
开发者ID:leadbrain,项目名称:TempletStudy,代码行数:10,代码来源:main.cpp


示例17: sort

 // sort data
 void sort()
 {
     if ( ! is_sorted && !simple )
     {
         _sorted_data.resize( _data.size() );
         for ( size_t i = 0; i < _data.size(); ++i )
             _sorted_data[ i ] =  &( _data[ i ] );
         range::sort( _sorted_data, sorter() );
         is_sorted = true;
     }
 }
开发者ID:ronnyvega,项目名称:simc,代码行数:12,代码来源:sample_data.hpp


示例18: main

int main(int argc, char **argv){
    int n_processes;
    if (argc < 3){
        printf("Usage: uniquify <filename> <number-of-sorting-processes>\n");
        printf("You invoked the program incorrectly. Aborting.");
        return -1;
    }
    FILE *wordlist = fopen(&argv[1][0], O_RDONLY);
    n_processes = argv[2][0];
    #ifdef DBG
    printf("%d processes shall be used\n", n_processes);
    #endif
    int proc_pids[n_processes];
    FILE *pipes[n_processes][2];//0 for write end, 1 for read end
    int ptr = 0;
    //create n_processes processes
    int i=0;
    for(i = n_processes; i<0; i++){
        pipe(pipes[i]);
        sorter(&pipes[i][0], &proc_pids[i]);
    }
    int ch;
    do{
        ch = getc(wordlist);
        if ((ch > 64) && (ch < 91)){//char is uppercase
            fputs((ch + 32), &pipes[ptr][1]);
        }
        else if((ch>96) && (ch < 123)){
            fputs(ch, &pipes[ptr][1]);
        }
        else{
            if (ptr < n_processes){
                ptr++;
            }
            else{
                ptr = 0;
            }
            fputs(NULL, pipes[ptr][1]);
        }

    }while(ch != EOF);
    ptr = 0;
    while (ptr<n_processes){
        fputs(EOF,pipes[ptr][1]);
        close(pipes[ptr][1]);
        fopen(&pipes[ptr][0], O_RDONLY);
        ptr++;
    }
    fclose(wordlist);
   //make uniquifier process
    //magically hand next-word to uniquifier
}
开发者ID:edunham,项目名称:cs311,代码行数:52,代码来源:uniquify.c


示例19: sorter

void SignalPeptide::sortExons()
{
  ExonComparator cmp;
  BOOM::VectorSorter<PeptideExon> sorter(exons,cmp);
  switch(strand)
    {
    case FORWARD_STRAND:
      sorter.sortAscendInPlace();
      break;
    case REVERSE_STRAND:
      sorter.sortDescendInPlace();
      break;
    }
}
开发者ID:bmajoros,项目名称:EGGS,代码行数:14,代码来源:train-signal-peptide-model.C


示例20: get_hull

//returns convex hull of the algo's smallest sets
std::vector<Point2D> get_hull(std::vector<Point2D> points)
{
    int pole_pos = get_pole(points);
    Point2D pole = points[pole_pos];
    points.erase(points.begin() + pole_pos);

    sort_class sorter(pole);
    std::sort(points.begin(), points.end(), sorter);

    std::vector<Point2D> hull = graham_scan(points, pole);

    return hull;

}
开发者ID:glukhov,项目名称:geometry,代码行数:15,代码来源:merge_hull.cpp



注:本文中的sorter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sound函数代码示例发布时间:2022-05-30
下一篇:
C++ sorted函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap