{"id":2442,"date":"2016-05-23T17:36:22","date_gmt":"2016-05-23T21:36:22","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=2442"},"modified":"2021-12-18T05:35:00","modified_gmt":"2021-12-18T10:35:00","slug":"modifying-algorithms","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/modifying-algorithms\/","title":{"rendered":"The C++ Standard Template Library Modifying Algorithms – Part 8"},"content":{"rendered":"\n

Welcome to the eighth and final part of our C++ Standard Template Library<\/a> series. In this eighth part, we will be discussing in brief Modifying Algorithms. This series comes to an end even though some quick and dirty research will show the STL is rather large.<\/p>\n\n\n\n

The reason we are stopping here is to change the focus to talking about other libraries like Boost<\/a> and Qt<\/a>. More importantly, we will be starting our C++<\/a> tutorial series on modern C++ which will include videos on our Partner YouTube Channel.<\/p>\n\n\n\n

As usual, if you are catching up with us now I would like to direct you to the start of this series<\/a>. If you have some knowledge in STL then you can fast track to ore recent articles in this series. So without much ado, we will pick up from where we left off on talking about Non-Modifying algorithms<\/a>.<\/p>\n\n\n\n

What are Modifying Algorithms?<\/h2>\n\n\n\n

In simplest terms, Modifying Algorithms can be described as those algorithms that alter the data on which they are applied to operate on. For example, if I apply an algorithm to change the order of elements in an array and return the array with the new order, that algorithm can be termed as a modifying algorithm.<\/p>\n\n\n\n

Again we will show you some of the common algorithms to illustrate how these algorithms are used. If you missed our article on Algorithms and Iterators you can go back to part six of this STL series and read that article<\/a> to brush up further on algorithms.<\/p>\n\n\n\n

Let’s start off by looking at some of the many copy algorithms. These basically modify the contents of the one variable based on the value of a different variable. Look at these examples:<\/p>\n\n\n\n

vector<int> src = {2,5,3}; \/\/ our source of data\nvector<int> dest = {0,0,0,0,0,0,0,0,0,0}; \/\/ array to be modified\n\n\/\/ Lets copy all of src to dest\ncopy(src.begin(), src.end(),dest.begin());\n\/\/ dest is now {2,5,3,0,0,0,0,0,0,0}\n\n\/\/ lets copy part of src to dest\ncopy_n(src.begin(), 2, dest.begin());\n\/\/ dest is now {2,5,0,0,0,0,0,0,0,0}\n\n\/\/lets copy to the end of dest\ncopy_backward(src.begin(), src.end(),dest.end());\n\/\/dest is now {0,0,0,0,0,0,0,2,5,3}<\/code><\/pre>\n\n\n\n

Now let’s take a look at moving some data around. Take a look at these examples:<\/p>\n\n\n\n

vector<int> src = {2,5,3}; \/\/ our source of data\nvector<int> dest = {0,0,0,0,0,0,0,0,0,0}; \/\/ array to be modified\n\n\/\/ Lets move all of src to dest\nmove(src.begin(), src.end(),dest.begin());\n\/\/ dest is now {2,5,3,0,0,0,0,0,0,0}\n\/\/ src is now undefined\n\n\/\/lets move src to the end of dest assuming its redefined\nmove_backward(src.begin(), src.end(),dest.end());\n\/\/dest is now {0,0,0,0,0,0,0,2,5,3}\n\/\/ src is now undefined<\/code><\/pre>\n\n\n\n

Here are a few last examples:<\/p>\n\n\n\n

vector<int> src = {2,5,3}; \/\/ our source of data\nvector<int> src2 = {7,8,9}; \/\/ 2nd source of data\nvector<int> dest = {0,0,0,0,0,0,0,0,0,0}; \/\/ array to be modified\n\n\/\/ Lets exchange contents of src and src2 \nswap_rages(src.begin(), src.end(),src2.begin());\n\/\/ src2 is now contents of src while\n\/\/ src is now contents or src2\n\n\/\/lets move src to the end of dest assuming its redefined\nfill(dest.begin(), dest.end(),1);\n\/\/all elements in dest are now 1\n\n\/\/replace all occurences of 6 with 5\nreplace(src.begin(), src.end(),6,5);\n\n\/\/remove all occurences of 7\nremove(src.begin(), src.end(),7);\n\n\/\/remove consequent equal elements\nunique(src.begin(), src.end());<\/code><\/pre>\n\n\n\n

There you have it. By now you should have a general idea about algorithms that do not modify data vs the modifying algorithms.<\/p>\n","protected":false},"excerpt":{"rendered":"

Welcome to the eighth and final part of our C++ Standard Template Library series. In this eighth part, we will be discussing in brief Modifying Algorithms. This series comes to…<\/p>\n","protected":false},"author":1,"featured_media":2443,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,27,16,20],"tags":[47,111,350,471,544,545,563,591],"yoast_head":"\nLearn About Modifying Algorithms in the 8th Part of C++ STL Series<\/title>\n<meta name=\"description\" content=\"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/modifying-algorithms\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn About Modifying Algorithms in the 8th Part of C++ STL Series\" \/>\n<meta property=\"og:description\" content=\"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/modifying-algorithms\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-23T21:36:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-18T10:35:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"The C++ Standard Template Library Modifying Algorithms – Part 8\",\"datePublished\":\"2016-05-23T21:36:22+00:00\",\"dateModified\":\"2021-12-18T10:35:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/\"},\"wordCount\":343,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg\",\"keywords\":[\"Algorithms\",\"C++\",\"Libraries\",\"Programming\",\"Software development\",\"Software Engineering\",\"STL\",\"Tools\"],\"articleSection\":[\"Articles\",\"Programming\",\"Technology\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/local.brightwhiz\/modifying-algorithms\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/\",\"url\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/\",\"name\":\"Learn About Modifying Algorithms in the 8th Part of C++ STL Series\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg\",\"datePublished\":\"2016-05-23T21:36:22+00:00\",\"dateModified\":\"2021-12-18T10:35:00+00:00\",\"description\":\"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/modifying-algorithms\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg\",\"width\":1200,\"height\":630,\"caption\":\"C++ STL Modifying Algorithms\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/modifying-algorithms\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The C++ Standard Template Library Modifying Algorithms – Part 8\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/x.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn About Modifying Algorithms in the 8th Part of C++ STL Series","description":"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/modifying-algorithms\/","og_locale":"en_US","og_type":"article","og_title":"Learn About Modifying Algorithms in the 8th Part of C++ STL Series","og_description":"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs","og_url":"http:\/\/local.brightwhiz\/modifying-algorithms\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2016-05-23T21:36:22+00:00","article_modified_time":"2021-12-18T10:35:00+00:00","og_image":[{"width":1200,"height":630,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"The C++ Standard Template Library Modifying Algorithms – Part 8","datePublished":"2016-05-23T21:36:22+00:00","dateModified":"2021-12-18T10:35:00+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/"},"wordCount":343,"commentCount":0,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg","keywords":["Algorithms","C++","Libraries","Programming","Software development","Software Engineering","STL","Tools"],"articleSection":["Articles","Programming","Technology","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/local.brightwhiz\/modifying-algorithms\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/","url":"http:\/\/local.brightwhiz\/modifying-algorithms\/","name":"Learn About Modifying Algorithms in the 8th Part of C++ STL Series","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg","datePublished":"2016-05-23T21:36:22+00:00","dateModified":"2021-12-18T10:35:00+00:00","description":"Here we continue with the 8th part of the C++ STL series by looking at modifying algorithms and how to use them when writing your programs","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/modifying-algorithms\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2016\/05\/stl-modifying-algorithms.jpg","width":1200,"height":630,"caption":"C++ STL Modifying Algorithms"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/modifying-algorithms\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"The C++ Standard Template Library Modifying Algorithms – Part 8"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/x.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/2442"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=2442"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/2442\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/2443"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=2442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=2442"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=2442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}