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


C++ DoubleLinkedList类代码示例

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


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

示例1: return

bool Test::test9()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        std::cerr << "Test 9: find returns false when value not in list:  ";

        //add values from 0 to TEST_SIZE-1 inclusively
        for(int i=0; i<TEST_SIZE; i++)
        {
                list.pushFront(i);
        }

        //find value not in list
        if( list.find(-1) == nullptr )
        {
                isPassed = true;
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return (isPassed);
}
开发者ID:austinBailey5624,项目名称:oldCPlusPlusProjects,代码行数:26,代码来源:Test.cpp

示例2: catch

bool Test::test25()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        std::cerr << "Test 25: insertBehind on empty list throws exception: ";

        try
        {
                list.insertBehind(0, 1);
        }
        catch(std::exception& e)
        {
                isPassed = true;
        }

        if(isPassed)
        {
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return(isPassed);
}
开发者ID:austinBailey5624,项目名称:oldCPlusPlusProjects,代码行数:27,代码来源:Test.cpp

示例3: TestFirstAndLast

void TestFirstAndLast(const DoubleLinkedList<int> & alist)
{
	DoubleLinkedList<int> blist;

	std::cout << "\n********** First and Last **********" << std::endl;

	// Full List
	std::cout << alist.First() << std::endl;
	std::cout << alist.Last() << std::endl;

	// Empty List
	try
	{
		std::cout << blist.First() << std::endl;
	}
	catch (char * msg)
	{
		std::cout << msg << std::endl;
	}
	try
	{
		std::cout << blist.Last() << std::endl;
	}
	catch (char * msg)
	{
		std::cout << msg << std::endl;
	}
}
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:28,代码来源:Main.cpp

示例4: TestFirstAndLast

void TestFirstAndLast(const DoubleLinkedList<int> & alist)
{
    DoubleLinkedList<int> blist;
    
    std::cout << "\n********** Testing: DoubleLinkedList First and Last **********" << std::endl;
    
    std::cout << "\n********** Testing: First and Last with Full List **********" << std::endl;
    std::cout << alist.First() << std::endl;
    std::cout << alist.Last() << std::endl;
    
    std::cout << "\n********** Testing: First with Empty List **********" << std::endl;
    try
    {
        std::cout << blist.First() << std::endl;
    }
    catch (const char * msg)
    {
        std::cout << msg << std::endl;
    }
    std::cout << "\n********** Testing: First with Empty List **********" << std::endl;
    try
    {
        std::cout << blist.Last() << std::endl;
    }
    catch (const char * msg)
    {
        std::cout << msg << std::endl;
    }
}
开发者ID:3jackdaws,项目名称:DoubleLL,代码行数:29,代码来源:stub.cpp

示例5: TestPurge

void TestPurge(DoubleLinkedList<int> alist)
{
    DoubleLinkedList<int> blist;
    
    std::cout << "\n********** Testing: DoubleLinkedList Purge with Full List **********" << std::endl;
    
    std::cout << "\n********** Testing: Before Purge Full List **********" << std::endl;
    std::cout << alist.getHead() << std::endl;
    std::cout << alist.getTail() << std::endl;
    
    alist.Purge();
    
    std::cout << "\n********** Testing: After Purge Full List **********" << std::endl;
    std::cout << alist.getHead() << std::endl;
    std::cout << alist.getTail() << std::endl;
    
    std::cout << "\n********** Testing: DoubleLinkedList Purge with Empty List **********" << std::endl;
    std::cout << "\n********** Testing: Before Purge Empty List **********" << std::endl;
    std::cout << alist.getHead() << std::endl;
    std::cout << alist.getTail() << std::endl;
    
    alist.Purge();
    
    std::cout << "\n********** Testing: After Purge Empty List **********" << std::endl;
    std::cout << alist.getHead() << std::endl;
    std::cout << alist.getTail() << std::endl;
}
开发者ID:3jackdaws,项目名称:DoubleLL,代码行数:27,代码来源:stub.cpp

示例6: main

void main()
{
	// Tests Canonical Functions
	DoubleLinkedList<int> alist;			//ctor
	DoubleLinkedList<int> blist(alist);		//copy ctor
	DoubleLinkedList<int> clist;

	clist = blist;							//= operator

	// Tests Mutators
	std::cout << alist.getHead() << std::endl;
	std::cout << alist.getTail() << std::endl;

	// Tests Methods
	
	TestAppend(alist);
	TestFirstAndLast(alist);
	TestPrepend(alist);
	TestPurge(alist);
	TestInsertBefore();
	TestInsertAfter();
	TestExtract();

	std::cout << "\n********** List Integrity **********" << std::endl;
	alist.PrintForwards();
	alist.PrintBackwards();

	//The memory leak tool detects leaks because alist isn't being destroyed before it is called
	//by calling the destructor or the following line of code, the list is destroyed and
	//there are no leaks:
	//alist.Purge();
	_CrtDumpMemoryLeaks();
}
开发者ID:Roastern,项目名称:School-Projects,代码行数:33,代码来源:main.cpp

示例7: Dijkstra

DoubleLinkedList<GraphNode *> Dijkstra(GraphNode *Start, GraphNode * End)
{
	Map<GraphNode *, DijkstraHelperNode *> NodeHelperMap;
	DoubleLinkedList<DijkstraHelperNode *> Visited;
	MinHeap<DijkstraHelperNode *> OpenHeap;
	DijkstraHelperNode *NewHelper = new DijkstraHelperNode();
	NewHelper->m_Node = Start;
	NewHelper->m_Cost = 0;
	NodeHelperMap.Insert(Start, NewHelper);
	OpenHeap.Insert(NewHelper);
	while(!OpenHeap.IsEmpty())
	{
		DijkstraHelperNode *CurrentHelperNode = OpenHeap.PopTop();
		assert(CurrentHelperNode != NULL);
		GraphNode *CurrentGraphNode = CurrentHelperNode->m_Node;
		assert(CurrentGraphNode != NULL);
		DoubleLinkedList<GraphEdge *> *CurrendEdges = CurrentGraphNode->GetEdges();
		DoubleListNode<GraphEdge *> *CurrentEdge = CurrentEdges.GetHead();
		while(CurrentEdge != NULL)
		{
			GraphNode *OtherNode = CurrentEdge->m_End;
			if(OtherNode == CurrentGraphNode)
			{
				OtherNode = CurrentEdge->m_Start;
			}
			assert(OtherNode != CurrentGraphNode);
			DijkstraHelperNode *NodeHelper = NodeHelperMap.GetValue(OtherNode);
			if(NodeHelper == NULL)
			{
 				NodeHelper = new DijkstraHelperNode();
				NodeHelper->m_Node = OtherNode;
				NodeHelperMap.Insert(OtherNode, NodeHelper);		
				OpenHeap.Insert(NodeHelper);
			}
			int CostToNode = CurrentHelperNode->m_Cost + CurrentEdge->m_Cost;
			if(CostToNode < NodeHelper->m_Cost)
			{		
				NodeHelper->m_Cost = CostToNode;
				NodeHelper->m_Previous = CurrentGraphNode;
				OpenHeap.Update(NodeHelper);
			}
			if(OtherNode == End)
			{
				break;
			}
		}
	}

	DoubleLinkedList<GraphNode *> Path;
	DijkstraHelperNode *EndHelper = NodeHelperMap.GetValue(End);
	if(EndHelper != NULL)
	{
		DijkstraHelperNode *CurrentHelper = EndHelper;
		while(CurrentHelper != NULL)
		{
			Path.AddFront(CurrentHelper->m_Node);
			CurrentHelper = CurrentHelper->m_Previous;
		}
	}
}
开发者ID:frods,项目名称:codebase,代码行数:60,代码来源:dijkstra.cpp

示例8: redirectOS

bool Test::test11()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        redirectOS();
        ss_redirect.clear();
        list.printList();
        restoreOS();

        std::cerr << "Test 10: printList prints empty string for empty list:  ";

        //Convert captured output to string and check length
        if(ss_redirect.str().length() == 0)
        {
                isPassed = true;
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return(isPassed);
}
开发者ID:austinBailey5624,项目名称:oldCPlusPlusProjects,代码行数:25,代码来源:Test.cpp

示例9: main

void main()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	// Tests Canonical Functions
	DoubleLinkedList<int> alist;			//ctor
	DoubleLinkedList<int> blist(alist);		//copy ctor
	DoubleLinkedList<int> clist;

	clist = blist;							//= operator

	// Tests Mutators
	std::cout << alist.getHead() << std::endl;
	std::cout << alist.getTail() << std::endl;

	// Tests Methods

	TestAppend(alist);
	TestFirstAndLast(alist);
	TestPrepend(alist);
	TestPurge(alist);
	TestInsertBefore();
	TestInsertAfter();
	TestExtract();

	std::cout << "\n********** List Integrity **********" << std::endl;
	alist.PrintForwards();
	alist.PrintBackwards();
}
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:29,代码来源:Main.cpp

示例10: remove

bool Test::test21()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        std::cerr << "Test 21: remove(value) where value is not in large list returns false\n";

        for(int i=0; i<TEST_SIZE; i++)
        {
                std::cerr << '\r' << "\tAdding " << (i+1) << "/" << TEST_SIZE << " nodes. ";
                list.pushBack(i);
                std::cerr.flush();
        }

        if( !list.remove(-1) )
        {
                isPassed = true;
        }

        if(isPassed)
        {
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return(isPassed);
}
开发者ID:austinBailey5624,项目名称:oldCPlusPlusProjects,代码行数:30,代码来源:Test.cpp

示例11: main

void main()
{
	// Tests Canonical Functions
	DoubleLinkedList<int> alist;			//ctor
	DoubleLinkedList<int> blist(alist);		//copy ctor
	DoubleLinkedList<int> clist;

	clist = blist;							//= operator

	// Tests Mutators
	std::cout << alist.getHead() << std::endl;
	std::cout << alist.getTail() << std::endl;

	// Tests Methods
	
	TestAppend(alist);
	TestFirstAndLast(alist);
	TestPrepend(alist);
	TestPurge(alist);
	TestInsertBefore();
	TestInsertAfter();
	TestExtract();

	std::cout << "\n********** List Integrity **********" << std::endl;
	alist.PrintForwards();
	alist.PrintBackwards();
	_asm nop;//added as a break point location;
}
开发者ID:robopanda333,项目名称:DataStructs,代码行数:28,代码来源:lab4stub.cpp

示例12: print

inline void print(DoubleLinkedList &dll1, DoubleLinkedList &dll2,
                  DoubleLinkedList &dll3, DoubleLinkedList &dll4)
{
    cout << "Size of the list1: " << dll1.getNumberElements() << endl;
    cout << "Size of the list2: " << dll2.getNumberElements() << endl;
    cout << "Size of the modList1: " << dll3.getNumberElements() << endl;
    cout << "Size of the modList2: " << dll4.getNumberElements() << endl << endl;
}
开发者ID:Ph0en1xGSeek,项目名称:ACM,代码行数:8,代码来源:main.cpp

示例13: TestAppend

void TestAppend(DoubleLinkedList<int> & alist)
{
	std::cout << "\n********** Append **********" << std::endl;

	alist.Append(5);
	alist.Append(15);
	alist.Append(25);
	alist.Append(35);
}
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:9,代码来源:Main.cpp

示例14: TestPurge

void TestPurge(DoubleLinkedList<int> alist)
{
	std::cout << "\n********** Purge **********" << std::endl;

	std::cout << alist.getHead() << std::endl;
	std::cout << alist.getTail() << std::endl;

	alist.Purge();

	std::cout << alist.getHead() << std::endl;
	std::cout << alist.getTail() << std::endl;
}
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:12,代码来源:Main.cpp

示例15: TestAppend

void TestAppend(DoubleLinkedList<int> & alist)
{
    std::cout << "\n********** Testing: DoubleLinkedList Append **********" << std::endl;
    
    alist.Append(5);
    alist.Append(15);
    alist.Append(25);
    alist.Append(35);
    
    std::cout << alist.First() << std::endl;
    std::cout << alist.Last() << std::endl;
}
开发者ID:3jackdaws,项目名称:DoubleLL,代码行数:12,代码来源:stub.cpp


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