当前位置: 首页>>代码示例>>C++>>正文


C++ SListPure::quicksort方法代码示例

本文整理汇总了C++中SListPure::quicksort方法的典型用法代码示例。如果您正苦于以下问题:C++ SListPure::quicksort方法的具体用法?C++ SListPure::quicksort怎么用?C++ SListPure::quicksort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SListPure的用法示例。


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

示例1: computeDFS

// start DFS-traversal
void BoyerMyrvoldInit::computeDFS()
{
	// compute random edge costs
	EdgeArray<int> costs;
	EdgeComparer comp;

	if(m_randomness > 0 && m_edgeCosts != nullptr) {
		costs.init(m_g);

		int minCost = std::numeric_limits<int>::max();
		int maxCost = std::numeric_limits<int>::min();

		for(edge e : m_g.edges) {
			minCost = min(minCost, (*m_edgeCosts)[e]);
			maxCost = min(maxCost, (*m_edgeCosts)[e]);
		}

		std::uniform_real_distribution<> urd(-1, 1);
		for(edge e : m_g.edges) {
			costs[e] = minCost + (int)((1 - m_randomness) * ((*m_edgeCosts)[e] - minCost) + m_randomness * (maxCost - minCost) * urd(m_rand));
		}

		comp.setCosts(&costs);
	} else if(m_edgeCosts != nullptr) {
		comp.setCosts(m_edgeCosts);
	}

	StackPure<adjEntry> stack;
	int nextDFI = 1;
	const int numberOfNodes = m_g.numberOfNodes();

	SListPure<adjEntry> adjList;
	SListPure<node> list;
	m_g.allNodes(list);

	// get random dfs-tree, if wanted
	if (m_randomness > 0) {
		list.permute();
	}

	for (node v : list) {
		if (v->degree() == 0) {
			m_dfi[v] = nextDFI;
			m_leastAncestor[v] = nextDFI;
			m_nodeFromDFI[nextDFI] = v;
			++nextDFI;
		} else {
			adjList.clear();
			m_g.adjEntries(v, adjList);
			adjList.quicksort(comp);
			m_g.sort(v, adjList);
			stack.push(v->firstAdj());
		}
	}

	while (nextDFI <= numberOfNodes) {
		OGDF_ASSERT(!stack.empty());
		adjEntry prnt = stack.pop();
		node v = prnt->theNode();
		// check, if node v was visited before.
		if (m_dfi[v] != 0) continue;
		// parentNode=nullptr on first node on connected component
		node parentNode = prnt->twinNode();
		if (m_dfi[parentNode] == 0) parentNode = nullptr;

		// if not, mark node as visited and initialize NodeArrays
		m_dfi[v] = nextDFI;
		m_leastAncestor[v] = nextDFI;
		m_nodeFromDFI[nextDFI] = v;
		++nextDFI;

		// push all adjacent nodes onto stack
		for(adjEntry adj : v->adjEdges) {
			edge e = adj->theEdge();
			if (adj == prnt && parentNode != nullptr) continue;

			// check for self-loops and dfs- and dfs-parallel edges
			node w = adj->twinNode();
			if (m_dfi[w] == 0) {
				m_edgeType[e] = EDGE_DFS;
				m_adjParent[w] = adj;
				m_link[CW][w] = adj;
				m_link[CCW][w] = adj;

				// found new dfs-edge: preorder
				stack.push(adj->twin());
			} else if (w == v) {
				// found self-loop
				m_edgeType[e] = EDGE_SELFLOOP;
			} else {
				// node w already has been visited and is an dfs-ancestor of v
				OGDF_ASSERT(m_dfi[w] < m_dfi[v]);
				if (w == parentNode) {
					// found parallel edge of dfs-parent-edge
					m_edgeType[e] = EDGE_DFS_PARALLEL;
				} else {
					// found backedge
					m_edgeType[e] = EDGE_BACK;
					// set least Ancestor
//.........这里部分代码省略.........
开发者ID:lncosie,项目名称:ogdf,代码行数:101,代码来源:BoyerMyrvoldInit.cpp


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