本文整理汇总了C++中DoublyLinkedList::removeLast方法的典型用法代码示例。如果您正苦于以下问题:C++ DoublyLinkedList::removeLast方法的具体用法?C++ DoublyLinkedList::removeLast怎么用?C++ DoublyLinkedList::removeLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoublyLinkedList
的用法示例。
在下文中一共展示了DoublyLinkedList::removeLast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: remove
double remove(int method) // 1: first; 2: last
{
if(!isEmpty())
{
double dd;
switch(method)
{
case 1:
dd = dll->removeFirst();
break;
case 2:
dd = dll->removeLast();
break;
default:
cout << "Deque::remove(): unknown remove method: remove first\n";
dd = dll->removeFirst();
break;
} // end switch
nElems--;
return dd;
} // end if
else
{
cout << "Deque::remove(): cannot remove, deque is empty\n";
return -1;
}
} // end remove()
示例2: 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;
}