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


C++ DynamicArray::Insert方法代码示例

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


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

示例1:

void TradeRouteData::ReturnPath
(
    const PLAYER_INDEX          owner,
    DynamicArray<MapPoint> &    waypoints,
    DynamicArray<MapPoint> &    fullpath,
	double &                    cost
)
{
	fullpath.Clear();
	Path partialAstarPath;
	float partialcost = 0;
	cost = 0.0;

	m_astarPath->Clear();

	int     nwp = waypoints.Num();
	sint32  r;

	for (int wp = 0; wp < nwp - 1; wp++)
    {
		if (wp == 0)
        {
			r = g_theTradeAstar.FindPath(owner, waypoints[wp], waypoints[wp + 1],
			                             *m_astarPath, partialcost, FALSE);
			Assert(r);
		} else {
			r = g_theTradeAstar.FindPath(owner, waypoints[wp], waypoints[wp + 1],
								  partialAstarPath, partialcost, FALSE);
			Assert(r);
			m_astarPath->Concat(partialAstarPath);
		}
		cost += partialcost;
	}

	fullpath.Insert(waypoints[0]);
	MapPoint pnt;
	m_crossesWater = FALSE;
	for (int p = 1; p < m_astarPath->Num(); p++) {
		WORLD_DIRECTION d;
		m_astarPath->GetCurrentDir(d);
		sint32 r = fullpath[p-1].GetNeighborPosition(d, pnt);
		Assert(r);
		if(r) {
			fullpath.Insert(pnt);
			if(g_theWorld->IsWater(pnt)) {
				m_crossesWater = TRUE;
			}
		}

		m_astarPath->IncDir();
	}
}
开发者ID:jleclanche,项目名称:darkdust-ctp2,代码行数:52,代码来源:TradeRouteData.cpp

示例2: main

int main(int argc, char* argv[])
{
    DynamicArray<double> numbers;

    printf("Test1 begins: ");
    try
    {
        numbers.GetMedian();
        printf("FAILED.\n");
    }
    catch(exception e)
    {
        printf("Passed.\n");
    }

    numbers.Insert(5);
    Test("Test2", numbers, 5);

    numbers.Insert(2);
    Test("Test3", numbers, 3.5);

    numbers.Insert(3);
    Test("Test4", numbers, 3);

    numbers.Insert(4);
    Test("Test6", numbers, 3.5);

    numbers.Insert(1);
    Test("Test5", numbers, 3);

    numbers.Insert(6);
    Test("Test7", numbers, 3.5);

    numbers.Insert(7);
    Test("Test8", numbers, 4);

    numbers.Insert(0);
    Test("Test9", numbers, 3.5);

    numbers.Insert(8);
    Test("Test10", numbers, 4);

    return 0;
}
开发者ID:oliviazqq,项目名称:ChineseCodingInterviewAppendix,代码行数:44,代码来源:StreamMedian.cpp

示例3: main

int main(int argc, char **argv)
{
	DynamicArray<int> a;

	std::cout << "Dynamic arrays" << std::endl;
	a.Print();

	a.Insert(4);
	a.Print();

	a.Insert(3);
	a.Print();

	a.Insert(2);
	a.Print();

	a.Insert(1);
	a.Print();

	a.Insert(0);
	a.Print();

	cout << "3rd element = " << a[2] << endl;

	a[2] = 10;
	a.Print();

	a.Remove(1);
	a.Print();

	a.Remove(2);
	a.Print();

	a.Remove(1);
	a.Print();

	a.Remove(0);
	a.Print();

	a.Remove(0);
	a.Print();

	// Double


	DynamicArray<double> b;

	std::cout << "Dynamic arrays (with double)" << std::endl;
	b.Print();

	b.Insert(4.44);
	b.Print();

	b.Insert(3.33);
	b.Print();

	b.Insert(2.22);
	b.Print();

	b.Insert(1.11);
	b.Print();

	b.Insert(0.00);
	b.Print();

	cout << "3rd element = " << b[2] << endl;

	b[2] = 10.10;
	b.Print();

	b.Remove(1);
	b.Print();

	b.Remove(2);
	b.Print();

	b.Remove(1);
	b.Print();

	b.Remove(0);
	b.Print();

	b.Remove(0);
	b.Print();
}
开发者ID:Sabreil,项目名称:School,代码行数:85,代码来源:main.cpp


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