{"id":1116,"date":"2017-03-29T06:53:12","date_gmt":"2017-03-29T13:53:12","guid":{"rendered":"http:\/\/somethingk.com\/main\/?p=1116"},"modified":"2017-03-29T06:53:12","modified_gmt":"2017-03-29T13:53:12","slug":"linked-list-remove-all","status":"publish","type":"post","link":"https:\/\/somethingk.com\/main\/linked-list-remove-all\/","title":{"rendered":"Linked List Remove All"},"content":{"rendered":"<section id=\"text-4\" class=\"widget boka-widget widget_text amr_widget\">\t\t\t<div class=\"textwidget\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-7619916617995509\"\r\n     data-ad-slot=\"9102150708\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script><\/div>\n\t\t<\/section>\n<p>Here is a short insert on how to remove all Nodes of X value from a list. I use recursion and I believe I&#8217;ve created a pretty clean solution. This requires Nodes found in my earlier <a href=\"http:\/\/somethingk.com\/main\/?p=1003\">post<\/a>.<\/p>\n<div class=\"snippetcpt-wrap\" id=\"snippet-1117\" data-id=\"1117\" data-edit=\"\" data-copy=\"\/main\/wp-json\/wp\/v2\/posts\/1116?snippet=17b1fac833&#038;id=1117\" data-fullscreen=\"https:\/\/somethingk.com\/main\/code-snippets\/search-and-remove-from-linked-list-in-c\/?full-screen=1\">\n\t\t\t\t<pre class=\"prettyprint linenums lang-c_cpp\" title=\"Search and Remove from Linked List in C++\">#include &quot;Node.h&quot;\r\n\r\nNode* head; \/\/contains the head of our linked list\r\n\r\n\/\/Run the search and remove on the linked list starting at the head\r\n\/\/target is the value we are trying to remove from our list\r\nvoid searchAndRemove(int target){\r\n    searchAndRemove(target, head);\r\n}\r\n\r\n\r\nvoid searchAndRemove(int target, Node*&amp; n){\r\n    if(n != nullptr){\r\n      if(n-&gt;data == target) { \/\/if we found our target\r\n        Node* temp = n;\r\n        n = n-&gt;next; \/\/delete and replace\r\n        delete temp; \/\/delete the node to clean up memory\r\n        searchAndRemove(target, n); \/\/continue the search, we need this to check the one used to replace\r\n      } else {\r\n        searchAndRemove(target, n-&gt;next); \/\/continue the search\r\n      }\r\n    }\r\n}<\/pre>\n\t\t\t<\/div>\n<p>Let me know if you have any comments or improvements!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a short insert on how to remove all Nodes of X value from a list. I use recursion and I believe I&#8217;ve created a pretty clean solution. This requires Nodes found in my earlier post. Let me know if you have any comments or improvements!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[177],"tags":[303,585,584,487],"class_list":["post-1116","post","type-post","status-publish","format-standard","hentry","category-development","tag-c","tag-linked-list","tag-remove","tag-search"],"_links":{"self":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":1,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/1116\/revisions"}],"predecessor-version":[{"id":1118,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/1116\/revisions\/1118"}],"wp:attachment":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/categories?post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/tags?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}