{"id":14699,"date":"2024-05-24T20:35:09","date_gmt":"2024-05-24T17:35:09","guid":{"rendered":"https:\/\/elzero.org\/?p=14699"},"modified":"2024-05-24T20:35:09","modified_gmt":"2024-05-24T17:35:09","slug":"implement-functions-with-cpp-if-in-array","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-if-in-array\/","title":{"rendered":"If In Array"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\n\/*\r\n  In Array -> In Container\r\n  In_Array({1, 2, 3, 4, 5}, 5) -> True\r\n  In_Array({1, 2, 3, 4, 5}, 6) -> False\r\n*\/\r\n\r\nbool in_array(vector<int> arr, int target)\r\n{\r\n  for (int i = 0; i < arr.size(); i++)\r\n  {\r\n    if (arr[i] == target)\r\n    {\r\n      return true;\r\n    }\r\n  }\r\n  return false;\r\n}\r\n\r\nint main()\r\n{\r\n  cout << boolalpha;\r\n  cout << in_array({1, 2, 3, 4, 5}, 3) << endl; \/\/ 1 -> True\r\n  cout << in_array({1, 2, 3, 4, 5}, 6) << endl; \/\/ 0 -> False\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14699","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14699"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14699\/revisions"}],"predecessor-version":[{"id":14700,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14699\/revisions\/14700"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}