本文整理汇总了C++中DoublyLinkedList::insertLast方法的典型用法代码示例。如果您正苦于以下问题:C++ DoublyLinkedList::insertLast方法的具体用法?C++ DoublyLinkedList::insertLast怎么用?C++ DoublyLinkedList::insertLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoublyLinkedList
的用法示例。
在下文中一共展示了DoublyLinkedList::insertLast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main () {
// Construct a linked list with header & trailer
cout << "Create a new list" << endl;
DoublyLinkedList<string> dll;
cout << "list: " << dll << endl << endl;
// Insert 10 nodes at back with value 10,20,30,..,100
cout << "Insert 10 nodes at back with value 10,20,30,..,100" << endl;
for (int i=10;i<=100;i+=10) {
stringstream ss;
ss << i;
dll.insertLast(ss.str());
}
cout << "list: " << dll << endl << endl;
// Insert 10 nodes at front with value 10,20,30,..,100
cout << "Insert 10 nodes at front with value 10,20,30,..,100" << endl;
for (int i=10;i<=100;i+=10) {
stringstream ss;
ss << i;
dll.insertFirst(ss.str());
}
cout << "list: " << dll << endl << endl;
// Copy to a new list
cout << "Copy to a new list" << endl;
DoublyLinkedList<string> dll2(dll);
cout << "list2: " << dll2 << endl << endl;
// Assign to another new list
cout << "Assign to another new list" << endl;
DoublyLinkedList<string> dll3=dll;
cout << "list3: " << dll3 << endl << endl;
// Delete the last 10 nodes
cout << "Delete the last 10 nodes" << endl;
for (int i=0;i<10;i++) {
dll.removeLast();
}
cout << "list: " << dll << endl << endl;
// Delete the first 10 nodes
cout << "Delete the first 10 nodes" << endl;
for (int i=0;i<10;i++) {
dll.removeFirst();
}
cout << "list: " << dll << endl << endl;
// Check the other two lists
cout << "Make sure the other two lists are not affected." << endl;
cout << "list2: " << dll2 << endl;
cout << "list3: " << dll3 << endl;
return 0;
}
示例2: insert
void insert(double dd, int method) // 1: first; 2: last
{
if(!isFull())
{
switch(method)
{
case 1:
dll->insertFirst(dd);
break;
case 2:
dll->insertLast(dd);
break;
default:
cout << "Deque::insert(): unknown insertion method: insert first\n";
dll->insertFirst(dd);
break;
} // end switch
nElems++;
} // end if
else
cout << "Deque::insert(): cannot insert "
<< dd << ", deque is full\n";
} // end insert()