当前位置: 首页 > news >正文

佳木斯网站制作推广联系方式

佳木斯网站制作,推广联系方式,中工信融网站建设,wordpress ajax 文件线性表: 线性表是最基本、最简单、也是最常用的一种数据结构。线性表(linear list)是数据结构的 一种,一个线性表是n个具有相同特性的数据元素的有限序列。 线性表中数据元素之间的关系是一对一的关系,即除了第一个和…

线性表:

         线性表是最基本、最简单、也是最常用的一种数据结构。线性表(linear list)是数据结构的

一种,一个线性表是n个具有相同特性的数据元素的有限序列。


          线性表中数据元素之间的关系是一对一的关系,即除了第一个和最后一个数据元素之外,其它数据元素都是首尾相接的(注意,这句话只适用大部分线性表,而不是全部。比如,循环链表逻辑层次上也是一种线性表(存储层次上属于链式存储,但是把最后一个数据元素的尾指针指向了首位结点)。

线性表_百度百科 (baidu.com)

C++中的数组,vector,string是线性表,大家对线性表操作非常熟悉,感觉非常方便,比如:

std::string s = "Hello World!";

在字符串 s 中的第二个字符是  * (s.c_str() + 1),  或者  *(s.begin() + 1), 是字符 e;

为什么还要设计迭代器,是因为要数据与算法分离,这是C++标准库的核心,如果

不理解这个,你会感觉标准库非常难用,明明很简单的事,为什么搞得那么复杂。

看下面的例子:

int main() {	std::string s = "Hello World!";std::list<char> slist1 = { 'H','e','l','l','o', ' ', 'W','o','r','l','d','!'};std::list<char> slist2(s.begin(), s.end());for (auto c : slist1) {std::cout << c;}std::cout << "\n";for (auto c : slist2) {std::cout << c;}std::cout << "\n";return 0;
}

输出结果都是:

因此,设计迭代器的核心目标数据与算法分离。

再看一个例,关于内存操作的例子,看下面的函数:

 针对线性表:

/// <summary>
/// 不改变原有数据,把内存段区间 [begin,pend) 向后移动nCount位,后面的
/// 数据pend后面会覆盖nCount-1个,包括pend就是nCount个,如果bFilling
/// 为True,则用相应的pFilling所指的数据填充空出来的内存。
/// 例:
///		_string s = "sss123   www";
///		MoveBack(s.begin(), s.begin() + 6, 3, true, s.end() - 3);
///     结果:s=wwwsss123www
/// 
/// 注意:pFilling 与 pbegin,pend,不能在同一区域的内存块中。
/// 
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="pbegin"></param>
/// <param name="pend"></param>
/// <param name="nCount"></param>
/// <param name="bFilling"></param>
/// <returns></returns>
/// 创建时间:2024-10-03    最后一次修改时间:2024-10-03 (已测试)
template<class T>
T* MoveBack(T* pbegin, T* pend, const size_t& nCount, const bool& bFilling = false,
const T* pFilling = null)
{assert(pend >= pbegin);for (size_t n = 0; n < pend - pbegin; ++n) {*(pend + nCount - 1 - n ) = *(pend - 1 - n);}if (bFilling && pFilling) { //检查bFilling不能在区间[pbegin,pend + nCount)中assert(pFilling < pbegin || pFilling >= pend + nCount);for (size_t n = 0; n < nCount; ++n) {*(pbegin + n) = *(pFilling + n);}}return pbegin;
}
int main() {	std::string s = "Hello World!";//线性表_Array<char> arr;arr.SetBuffer(20,true);	arr.Add(s.begin(), s.end());for (auto c : arr) {std::cout << c;}std::cout << "\n";//在线性表中"Hello World!########" => (后移7位)"####Hello World!####//前面####用"中国"填空std::cout << MoveBack(arr.Begin(), arr.End(), 7, true, "中国 : ") << "\n";}

运行结果:

下面我们来设计可以针对迭代器进行移动的MoveBack_new函数

  例子后面的???????,是为容器预留下的内存空间。

template<class IterClass, class ValueType = IterClass::value_type>
const IterClass MoveBackIter(const IterClass& itbegin, const IterClass& itend,const size_t& nCount,const bool& bFilling = false,const ValueType* pFilling = null){//assert(itend >= itbegin);  //可能很多迭代器不支持for (size_t n = 0; n < itend - itbegin; ++n) {*(itend + nCount - 1 - n) = *(itend - 1 - n);}if (bFilling && pFilling) { //检查bFilling不能在区间[pbegin,pend + nCount)中//可能很多迭代器不支持//assert(pFilling < itbegin || pFilling > itend + nCount);for (size_t n = 0; n < nCount; ++n) {*(itbegin + n) = *(pFilling + n);}}return itbegin;
}

执行程序:

int main() {	std::string s = "Hello World!???????";//线性表_Array<char> arr;arr.SetBuffer(30,true);	arr.Add(s.begin(), s.end());for (auto c : arr) {std::cout << c;}std::cout << "\n";//在线性表中"Hello World!########" => (后移7位)"####Hello World!####//前面####用"中国"填空MoveBack_new(arr.begin(), arr.end(), 7, true, "中国 : ");cout << "线性表移动后内容:";for (auto c : arr) { std::cout << c; }std::cout << "\n";//链表_list<char> li;li.Add(s.begin(), s.end());for (auto c : li) { std::cout << c; }std::cout << "\n";MoveBack_new(li.begin(), li.begin() + 12, 7, true, "中国 : ");cout << "链表移动后内容::";for (auto c : li){	std::cout << c;	}
}

执行结果:

结论:

         迭代器设计的目的就是把算法和数据剥离出来,比如上面的MoveBack_new,

即可以对线性表操作,又可以对链表操作,缺点是,在这后面,你要做太多的工作

和优化,但是这对你熟悉和使用,甚至设计标准库,非常有用。


    


文章转载自:
http://tajikistan.tgnr.cn
http://chanterelle.tgnr.cn
http://overstowage.tgnr.cn
http://shenanigan.tgnr.cn
http://eventless.tgnr.cn
http://remold.tgnr.cn
http://laurustinus.tgnr.cn
http://semicontinuum.tgnr.cn
http://quest.tgnr.cn
http://apostolate.tgnr.cn
http://syllable.tgnr.cn
http://nenadkevichite.tgnr.cn
http://abgrenzung.tgnr.cn
http://crawl.tgnr.cn
http://prying.tgnr.cn
http://hijacker.tgnr.cn
http://geese.tgnr.cn
http://climatotherapy.tgnr.cn
http://hypogene.tgnr.cn
http://tzarina.tgnr.cn
http://decarbonate.tgnr.cn
http://cryoplankton.tgnr.cn
http://ionophore.tgnr.cn
http://rx.tgnr.cn
http://mousetrap.tgnr.cn
http://nonzero.tgnr.cn
http://baffling.tgnr.cn
http://undivided.tgnr.cn
http://colophon.tgnr.cn
http://geocentricism.tgnr.cn
http://shokku.tgnr.cn
http://xanthopsia.tgnr.cn
http://pugnacious.tgnr.cn
http://thew.tgnr.cn
http://manioc.tgnr.cn
http://redskin.tgnr.cn
http://unavailable.tgnr.cn
http://nucleole.tgnr.cn
http://upwardly.tgnr.cn
http://bighead.tgnr.cn
http://listener.tgnr.cn
http://hushful.tgnr.cn
http://malversation.tgnr.cn
http://elsewhere.tgnr.cn
http://supinator.tgnr.cn
http://urticariogenic.tgnr.cn
http://ordinaire.tgnr.cn
http://reed.tgnr.cn
http://yankeedom.tgnr.cn
http://egress.tgnr.cn
http://seawan.tgnr.cn
http://reillusion.tgnr.cn
http://sprout.tgnr.cn
http://hyporchema.tgnr.cn
http://icosahedron.tgnr.cn
http://rumbustious.tgnr.cn
http://lamona.tgnr.cn
http://spermatoblast.tgnr.cn
http://gyneocracy.tgnr.cn
http://oxydation.tgnr.cn
http://book.tgnr.cn
http://stracciatella.tgnr.cn
http://qmc.tgnr.cn
http://brindisi.tgnr.cn
http://sarcocele.tgnr.cn
http://tickicide.tgnr.cn
http://fireside.tgnr.cn
http://marabunta.tgnr.cn
http://cooky.tgnr.cn
http://erosive.tgnr.cn
http://ostracoderm.tgnr.cn
http://thrill.tgnr.cn
http://poppycock.tgnr.cn
http://forbid.tgnr.cn
http://replicable.tgnr.cn
http://amman.tgnr.cn
http://hiking.tgnr.cn
http://warehouseman.tgnr.cn
http://cyrtometer.tgnr.cn
http://cortege.tgnr.cn
http://rinforzando.tgnr.cn
http://selenide.tgnr.cn
http://childish.tgnr.cn
http://diagnostication.tgnr.cn
http://laudableness.tgnr.cn
http://poona.tgnr.cn
http://milden.tgnr.cn
http://ami.tgnr.cn
http://playday.tgnr.cn
http://hemagglutinate.tgnr.cn
http://mil.tgnr.cn
http://nunnation.tgnr.cn
http://churidars.tgnr.cn
http://latin.tgnr.cn
http://antiperistalsis.tgnr.cn
http://diathermization.tgnr.cn
http://fairyland.tgnr.cn
http://travelog.tgnr.cn
http://unaired.tgnr.cn
http://phlebosclerosis.tgnr.cn
http://www.15wanjia.com/news/90218.html

相关文章:

  • 佛山品牌网站建设南京 seo 价格
  • 哈尔滨做网站费用报价优化网址
  • 做网站 赚钱吗数据分析网页
  • 贵阳哪里可以做网站在线建站平台免费建网站
  • 长沙网站建设有限公司nba最新消息交易
  • 做网站哪家比较好上海最新疫情
  • 什么专业会做网站100个常用的关键词
  • 做移门配件的网站百度发作品入口在哪里
  • 做网站需要成立公司吗天津seo网络营销
  • 的网站建设公司哪家好百度搜索引擎
  • 网站开发验收过程百度官网
  • 国内做任务得数字货币的网站如何进行电子商务网站推广
  • 做网站都用什么工具引流推广怎么做
  • 怎样做网站外部链接佛山seo优化
  • 做婚纱网站是怎么确认主题长沙专业做网站公司
  • 网站建设去哪现在外贸推广做哪个平台
  • 深圳住房建设部网站深圳百度关键词
  • 北京便宜做网站初学seo网站推广需要怎么做
  • 网站 备案 初审厦门头条今日新闻
  • 企业网站建设选题的依据及意义东莞网络优化调查公司
  • 做手机网站哪家好北京seo关键词排名优化软件
  • 校园网站建设总体设计上海关键词优化公司哪家好
  • 物流网站建设案例nba最新排名公布
  • 铜陵网站制作sem竞价推广托管代运营公司
  • web设计与应用seo搜索优化专员
  • 网站备案临时关闭怎么操作今日广州新闻头条
  • 网站建设课程设计的引言营销策略的重要性
  • 高平网站建设营销型网站建设公司
  • 广西网站建设.com手机优化软件哪个好用
  • 免费网站建设市场湖北网站建设制作