本文整理汇总了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);
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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;
}
}
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}