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


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

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


在下文中一共展示了DoublyLinkedList::insertFirst方法的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;
}
开发者ID:cjbrooks12,项目名称:CSCE,代码行数:55,代码来源:TemplateMain.cpp

示例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()
开发者ID:charlie-lee,项目名称:sams_data_structure_and_algorithms,代码行数:23,代码来源:deque.cpp


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