C++-----列表 list

列表list

        列表的核心是一个双向链表,双向开口,可在头、尾两个方向进行元素的插入和删除,因此list除了提供与vector相同的push_back(),和pop_back(),之外还提供在头部进行数据输入输出的操作函数。push_front()和pop_front()。因为链表内存空间不连续,所以不支持随即操作,既没有at()操作也不支持下标访问,只能从头到尾的顺序操作。

        下表为list 构造函数。

语句说明
list();创建一个空列表
list(size_type n);创建一个包含n个元素的列表
list(const list& x);创建一个列表使用列表x初始化它

template<class InputIterator>

list(InputIterator first,InputIterator last);

创建一个列表,并以迭代器first~last区域元素初始化

 

        list重载了operator= 用户可以在两个list对象之间复制数据。下表为数据元素的插入和删除:

        

函数说明

void assign(InputIterator _First,InputIterator _Last);

void assign(size_type _count, const Type& _val);

区域复值函数
void push_back(Type&& _Val);增加一个元素到链表尾
void push_front(Type&& _Val);增加一个元素到链表头
void pop_back();删除链表尾一个元素
void pop_front();删除链表头一个元素
void clear();删除所有元素

iterator erase(iterator _Where);

iterator erase(iterator _Fist,iterator _Last);

删除一个元素或一个区域的元素
void remove(const Type& _Val); 删除链表中匹配值的元素

template<class Predicate>

void remove_if(Predicate _Pred);

删除条件满足的元素(遍历一次链表),参数为自定义的回调函数

iterator insert(const _iterator _where,const& _)Val);

iterator insert(const_iterator _where ,Type&& _Val);

void inset(iterator _Where,size_type _Count,const Type& _Val);

template<class InputIterator>

void insert(iterator _Where,InputIterator _First,InputIterator _Last);

 

在指定位置插入一个或多个元素,有重载函数

void unique();

template<class BinaryPredicate>

void unique(BinaryPredicate _Pred);

删除重复相邻元素

reference front();

const_reference front() const;

返回第一个元素的引用
reference back();
  const_reference back() const;
返回最后一个元素的引用

        可以返回list关键迭代器的函数

       

函数说明

iterator begin();

const_iterator begin() const;

返回第一个元素的指针

iterator end();

const_iterator end() const;

返回最后一个元素的下一位置指针

iterator rbegin();

const_iterator rebgin() const;

返回链表的最后一个元素的后向指针

iterator rend();

const_iterator rend() const;

返回链表第一元素的后向指针

        可以提供list状态的函数

       

函数说明
bool empty() const;用于判断链表是否为空
size_type max_size() const;返回链表最大可能长度
size_type size() const;返回链表中元素个数
void resize(size_type n,value_type val=value_type());重新定义链表长度
void reverse();反转链表

void sort();

template<class Compare>

void sort(Compare comp);

对链表排序默认升序

void merge(list &x);

template <class StrictWeakOrdering>

void merge(list&, StrictWeakOrdering);

对两个有序链表进行合并使之有序

 void splice(iterator position, list& x);

void splice(iterator position, list&, iterator i);

void splice(iterator position, list&, iterator first, iterator last);

对两个链表进行结合
void swap(list &x);交换两个链表
#include<iostream>
#include<list>
using namespace std;
int main()
{
	list<int>::const_iterator cIter;
	//定义列表
	list<int>c1;
	//在列表尾部赋值
	c1.push_back(10);
	//在列表头部赋值
	c1.push_front(20);
	c1.push_front(30);
	//显示c1内容
	cout<<"c1=";
	for(auto &i:c1)
	  cout<<" "<<i;
	cout<<endl;
	//定义c2并在尾部赋值
	list<int>c2;
	c2.push_back(400);
	c2.push_back(500);
	c2.push_back(600);
	//清空c1
	c1.clear();
	//使用c2的后两个元素为c1赋值
	c1.assign(++c2.begin(),c2.end());
   //再显示c1内容
	cout<<"c1=";
	for(auto &i:c1)
	  cout<<" "<<i;
	cout<<endl;
	c1.clear();
	//c1赋值7个4
	c1.assign(7,4);
//显示c1内容
	cout<<"c1=";
	for(auto &i:c1)
	  cout<<" "<<i;
	cout<<endl;
	c1.clear();
	//列表初始化
	c1={9,8,7,6,2};
//显示c1内容
	cout<<"c1=";
	for(auto &i:c1)
	  cout<<" "<<i;
	cout<<endl;
}

        运行结果:

         

        g++编译时记得使用c++11标准。

 

 

 

        

 

  • 9
    点赞
  • 95
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Note that this is a text-only and possibly out-of-date version of the wiki ReadMe, which is located at: http://code.google.com/p/tesseract-ocr/wiki/ReadMe Introduction ============ This package contains the Tesseract Open Source OCR Engine. Originally developed at Hewlett Packard Laboratories Bristol and at Hewlett Packard Co, Greeley Colorado, all the code in this distribution is now licensed under the Apache License: ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. Dependencies and Licenses ========================= Leptonica is required. (www.leptonica.com). Tesseract no longer compiles without Leptonica. Libtiff is no longer required as a direct dependency. Installing and Running Tesseract -------------------------------- All Users Do NOT Ignore! The tarballs are split into pieces. tesseract-x.xx.tar.gz contains all the source code. tesseract-x.xx.<lang>.tar.gz contains the language data files for <lang>. You need at least one of these or Tesseract will not work. Note that tesseract-x.xx.tar.gz unpacks to the tesseract-ocr directory. tesseract-x.xx.<lang>.tar.gz unpacks to the tessdata directory which belongs inside your tesseract-ocr directory. It is therefore best to download them into your tesseract-x.xx directory, so you can use unpack here or equivalent. You can unpack as many of the language packs as you care to, as they all contain different files. Note that if you are using make install you should unpack your language data to your source tree before you run make install. If you unpack them as root to the destination directory of make install, then the user ids and access permissions might be messed up. boxtiff-2.xx.<lang>.tar.gz contains data that was used in training for those that want to do their own training. Most users should NOT download these files. Instructions for using the training tools are documented separately at Tesseract wiki http://code.google.com/p/tesseract-ocr/w/list Windows ------- Please use installer (for 3.00 and above). Tesseract is library with command line interface. If you need GUI, please check AddOns wiki page http://code.google.com/p/tesseract-ocr/wiki/AddOns#GUI If you are building from the sources, the recommended build platform is VC++ Express 2008 (optionally 2010). The executables are built with static linking, so they stand more chance of working out of the box on more windows systems. The executable must reside in the same directory as the tessdata directory or you need to set up environment variable TESSDATA_PREFIX. Installer will set it up for you. The command line is: tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfiles...] If you need interface to other applications, please check wrapper section on AddOns wiki page: http://code.google.com/p/tesseract-ocr/wiki/AddOns#Tesseract_3.0x Non-Windows (or Cygwin) ----------------------- You have to tell Tesseract through a standard unix mechanism where to find its data directory. You must either: ./autogen.sh ./configure make make install sudo ldconfig to move the data files to the standard place, or: export TESSDATA_PREFIX="directory in which your tessdata resides/" In either case the command line is: tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfiles...] New there is a tesseract.spec for making rpms. (Thanks to Andrew Ziem for the help.) It might work with your OS if you know how to do that. If you are linking to the libraries, as Ocropus does, please link to libtesseract_api. History ======= The engine was developed at Hewlett Packard Laboratories Bristol and at Hewlett Packard Co, Greeley Colorado between 1985 and 1994, with some more changes made in 1996 to port to Windows, and some C++izing in 1998. A lot of the code was written in C, and then some more was written in C++. Since then all the code has been converted to at least compile with a C++ compiler. Currently it builds under Linux with gcc4.4.3 and under Windows with VC++2008. The C++ code makes heavy use of a list system using macros. This predates stl, was portable before stl, and is more efficient than stl lists, but has the big negative that if you do get a segmentation violation, it is hard to debug. The most recent change is that Tesseract can now recognize 39 languages, including Arabic, Hindi, Vietnamese, plus 3 Fraktur variants is fully UTF8 capable, and is fully trainable. See TrainingTesseract for more information on training. Tesseract was included in UNLV's Fo
STL是指标准模板库(Standard Template Library),它是C++语言的一部分,提供了一系列的模板类和函数,用于支持通用的数据结构和算法。STL的目标是提供高效、可重用和可扩展的组件,以便开发人员能够更轻松地编写高质量的代码。STL包含了许多常见的数据结构,如vector、list、set、map等,以及各种算法,比如排序、查找、遍历等。通过使用STL,开发人员可以更加高效地处理各种数据结构和算法的问题,提高代码的开发效率和质量。 在STL中,我们可以使用各种容器来存储和管理数据。例如,我们可以使用std::map来创建一个键值对的映射,其中每个键都有一个与之相关联的值。下面是一个示例代码,展示了如何创建和使用一个std::map对象: std::map<std::string, int> disMap() { std::map<std::string, int> tempMap{ {"C语言教程",10},{"STL教程",20} }; return tempMap; } std::map<std::string, int> newMap(disMap()); 在这个示例中,disMap()函数创建了一个临时的std::map对象,并初始化了其中的一些键值对。然后,使用移动构造函数将这个临时对象移动到了一个新的std::map对象newMap中。最终,我们可以通过newMap对象来访问和操作这些键值对。 综上所述,STL是C++中的标准模板库,提供了一系列的模板类和函数,用于支持通用的数据结构和算法。STL的使用可以提高代码的开发效率和质量,并且通过各种容器和算法,可以方便地处理各种数据结构和算法的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [C++ STL详解超全总结(快速入门STL)](https://blog.csdn.net/qq_50285142/article/details/114026148)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【C++实验】阅读STL源码并分析](https://blog.csdn.net/qq_35760825/article/details/125311509)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值