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


C++ DoublyLinkedList::pop_back方法代码示例

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


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

示例1: main

int main()
{
	DoublyLinkedList *ls = new DoublyLinkedList();
	ls->push_back(*(new ListNode("100")));
	ListNode *n1 = new ListNode("5");
	ls->push_front(*n1);
	ls->push_front(*(new ListNode("1")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("0")));
	ls->push_back(*(new ListNode("1sdsd")));
	ls->print();
	cout << "\n";
	ls->print_bkw();
	cout << "\nLink list size is equal to " << ls->size() << endl;
	cout << "\n";
	cout << "Lets delete first and last nodes from list\n";
	ls->pop_back();
	ls->pop_front();
	ls->print();
	cout << "\nNow lets erase 4, 1 and 100: \n";
	ls->erase("4");
	ls->erase("1");
	ls->erase("100");
	ls->print();
	cout << "\nLets insert '6' after '3' and '7' after '5': \n";
	ls->insert_after("3", *(new ListNode("6")));
	ls->insert_after("5", *(new ListNode("7")));
	ls->print();
	cout << "\nLets clear linked list (check this with 'isEmpty' method): \n";
	ls->clear();
	if (ls->isEmpty())
		cout << "Our list is empty! \n";
	cout << "\nLets get new list: \n";
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("31")));
	ls->push_front(*(new ListNode("55")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("1")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("8"))); 
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("0")));
	ls->print();
	cout << "\nOur new sorted list: \n";
	ls->sort();
	ls->print();
	cout << "\nLets delete unique elements: \n";
	ls->unique();
	ls->print();
	cout << "\nLets insert '0', '2', '7' and '9' preserving list ordering: \n";
	ls->insert_ord(*(new ListNode("0")));
	ls->insert_ord(*(new ListNode("2")));
	ls->insert_ord(*(new ListNode("7")));
	ls->insert_ord(*(new ListNode("9")));
	ls->print();

	cout << "\nLets get new list 'temp_ls': \n";
	DoublyLinkedList *temp_ls = new DoublyLinkedList();
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("v")));
	temp_ls->push_front(*(new ListNode("a")));
	temp_ls->push_front(*(new ListNode("d")));
	temp_ls->print();
	cout << "\nLets 'merge' our lists (temp_ls in ls): \n";
	ls->merge(*temp_ls);
	ls->print();
	if (temp_ls->isEmpty())
		cout << "Our 'temp_ls' list is empty! \n";
	cout << "\nLets get new lists: \n";
	ls->clear();
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("4")));
	ls->push_front(*(new ListNode("1")));
	cout << "New 'ls': ";
	ls->print();
	temp_ls->push_front(*(new ListNode("b")));
	temp_ls->push_front(*(new ListNode("v")));
	temp_ls->push_front(*(new ListNode("a")));
	temp_ls->push_front(*(new ListNode("d")));
	cout << "New 'temp_ls': ";
	temp_ls->print();
	cout << "\nLets assign 'ls' to 'temp_ls' from 1 to 3: \n";
	ls->assign(*temp_ls, 1, 3);
	cout << "New 'ls': ";
	ls->print();
	cout << "New 'temp_ls': ";
	temp_ls->print();
	cout << "\nLets splice 'temp_ls' in 'ls' from index 3 with all list:\n ";
	ls->splice(3, *temp_ls);
	ls->print();
	ls->clear();
	temp_ls->clear();
	ls->push_front(*(new ListNode("6")));
	ls->push_front(*(new ListNode("3")));
	ls->push_front(*(new ListNode("5")));
	ls->push_front(*(new ListNode("4")));
//.........这里部分代码省略.........
开发者ID:Caparow,项目名称:CPP-tasks,代码行数:101,代码来源:TestAndDemonstration.cpp

示例2: testDoublyLinkedListAuto

bool testDoublyLinkedListAuto() {
	DoublyLinkedList list;
	list.push_back(5.0);
	if (list.is_empty() || list.get_head()->get_value() != 5.0) {
		return false;
	}
	if (list.is_empty() || list.get_tail()->get_value() != 5.0) {
		return false;
	}

	list.push_front(2.3);
	if (list.is_empty() || list.get_head()->get_value() != 2.3) {
		return false;
	}
	if (list.is_empty() || list.get_tail()->get_value() != 5.0) {
		return false;
	}

	list.push_back(3.7);
	list.push_front(4.2);

	if (list.is_empty() || list.get_head()->get_value() != 4.2) {
		return false;
	}
	if (list.is_empty() || list.get_tail()->get_value() != 3.7) {
		return false;
	}

	list.print_list();
	list.pop_front();
	list.pop_front();
	list.pop_front();
	list.pop_front();
	list.pop_front();
	list.print_list();

	list.push_back(6.66);

	if (list.is_empty() || list.get_head()->get_value() != 6.66) {
		return false;
	}
	if (list.is_empty() || list.get_tail()->get_value() != 6.66) {
		return false;
	}

	list.push_front(3.33);
	list.push_back(3.14);

	if (list.is_empty() || list.get_head()->get_value() != 3.33) {
		return false;
	}
	if (list.is_empty() || list.get_tail()->get_value() != 3.14) {
		return false;
	}

	list.print_list();

	list.pop_back();
	list.pop_back();
	list.pop_back();

	list.print_list();

	return true;
}
开发者ID:rkoch,项目名称:uzh-inf02b-a3,代码行数:65,代码来源:main.cpp


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