{"id":343,"date":"2014-10-25T11:51:12","date_gmt":"2014-10-25T11:51:12","guid":{"rendered":"http:\/\/www.mahmuttalhakoz.com\/blog\/?p=343"},"modified":"2014-10-25T11:51:12","modified_gmt":"2014-10-25T11:51:12","slug":"union-intersection-islemleri","status":"publish","type":"post","link":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/2014\/10\/25\/union-intersection-islemleri\/","title":{"rendered":"Union-InterSection \u0130\u015flemleri"},"content":{"rendered":"<p>Dizilerde Birle\u015fim(Union) ve Kesi\u015fim(Intersection) i\u015flemlerini a\u015fa\u011f\u0131daki \u015fekilde yapabiliriz.<\/p>\n<p>\u00d6ncelikle iki adet int tipinde dizi tan\u0131yoruz ve bu dizilere de\u011ferler at\u0131yoruz. De\u011fer atama i\u015flemini kullan\u0131c\u0131 yapacak \u015fekilde d\u00fczenleyebilirsiniz.<\/p>\n<p><code><br \/>\nint[] Array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,15,17,19,18,25,122,23 };<br \/>\nint[] Array2 = {3, 4, 5, 6, 7, 8, 9,13,15,18,12,23,122,51,25,1907,251 };<br \/>\n<\/code><\/p>\n<p>InterSection metodu ile dizilerde kesi\u015fim i\u015flemini yap\u0131yoruz.<\/p>\n<p><code>            public static int[] InterSection(int[] a, int[] b)<br \/>\n            {<br \/>\n                int[] InterSection1;<br \/>\n                if(a.Length>b.Length)<br \/>\n                    InterSection1= new int[a.Length];<br \/>\n                else<br \/>\n                    InterSection1= new int[b.Length];<\/p>\n<p>                int count=0;<br \/>\n                for (int i = 0; i < a.Length; i++)\n                {\n                    for (int j = 0; j < b.Length; j++)\n                    {\n                        if (a[i] == b[j])\n                        {\n                            InterSection1[count] = a[i];\n                            count++;\n                        }\n                    }\n                }\n                return InterSection1;\n            }\n<\/code><\/p>\n<p>Intersection- Kesi\u015fim olay\u0131n\u0131 yazd\u0131r\u0131yoruz.<br \/>\n<code><br \/>\n  foreach (int item in InterSection(Array1, Array2))<br \/>\n            {<br \/>\n                Console.WriteLine(item);<br \/>\n            }<br \/>\n            Console.WriteLine(\"Used to InterSection\\r\\n\\r\\n\");<br \/>\n<\/code><\/p>\n<p>Union-Birle\u015fim olay\u0131n\u0131 bu metod ile yap\u0131yoruz.<br \/>\n<code><br \/>\npublic static int[] Union(int[] a, int[] b)<br \/>\n            {<br \/>\n                int[] union = new int[a.Length + b.Length];<br \/>\n                int count=0;<br \/>\n                foreach (int itemA in a)<br \/>\n                {<br \/>\n                    union[count] = itemA;<br \/>\n                    count++;<br \/>\n                }<\/p>\n<p>                int[] newnumber=new int[b.Length];<\/p>\n<p>                foreach (int itemU in union)<br \/>\n                {<br \/>\n                    for (int i = 0; i < b.Length; i++)\n                    {\n                        if (itemU == b[i])\n                        {\n                            newnumber[i] = i;\n                            break;\n                        }\n                    }\n                }\n\n                for (int i = 0; i < b.Length; i++)\n                {\n                    if (i != newnumber[i])\n                    {\n                        union[count] = b[i];\n                        count++;\n                    }\n                }\n                return union;\n            }\n<\/code><\/p>\n<p>Ekrana yazd\u0131rma i\u015flemi de ayn\u0131 Intersection(Kesi\u015fim) i\u015fleminde oldu\u011fu gibi olacak.<\/p>\n<p><code><br \/>\nforeach (int item in Union(Array1,Array2))<br \/>\n            {<br \/>\n                if(item!=0)<br \/>\n                Console.WriteLine(item);<br \/>\n            }<br \/>\n            Console.WriteLine(\"Used to Union\");<br \/>\n            Console.ReadKey();<br \/>\n<\/code><\/p>\n<p>Union(Birle\u015fim) metodunu k\u0131sacak a\u00e7\u0131klamak gerekirse \"a\" dizisindeki t\u00fcm elemanlar\u0131 \"union\" dizisine at\u0131yoruz ve ard\u0131ndan bu dizideki elemanlar\u0131n\u0131n hangilerinin \"b\" dizisnde mevcut oldu\u011funu tespit ediyoruz. \"b\" dizisinde varolan elemanlar\u0131n indis numaras\u0131n\u0131 \"newnumber\" ad\u0131nda olu\u015fturdu\u011fumuz yeni bir diziye indisleriyle at\u0131yoruz. Son olarak \"b\" dizisinde eklenmeyen elemanlar\u0131 \"union\" dizisine ekleyerek i\u015flemi tamaml\u0131yoruz.<\/p>\n<p>Tabii ki alternatif ve tek sat\u0131rl\u0131k y\u00f6ntemler de yok de\u011fil ki yukardaki vb. y\u00f6ntemleri se\u00e7mek de o \u015fekilde istenmedi\u011fi s\u00fcrece mant\u0131kl\u0131 olmayacak.<\/p>\n<p>Tek sat\u0131rl\u0131k \"InterSect\" ve \"Union\" kodlar\u0131 \u015fu \u015fekilde;<\/p>\n<p><code><br \/>\n            int[] Array1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,15,17,19,18,25,122,23 };<br \/>\n            int[] Array2 = {3, 4, 5, 6, 7, 8, 9,13,15,18,12,23,122,51,25,1907,251 };<\/p>\n<p>            var Arrays = Array1.Union(Array2);<br \/>\n            var Arrays2 = Array1.Intersect(Array2);<br \/>\n<\/code><\/p>\n<p>\"Arrays\" ve \"Arrays\" iki dizilerindeki elemanlar\u0131 \u00e7ekerek ekranda g\u00f6sterebilirsiniz.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dizilerde Birle\u015fim(Union) ve Kesi\u015fim(Intersection) i\u015flemlerini a\u015fa\u011f\u0131daki \u015fekilde yapabiliriz. \u00d6ncelikle iki<span class=\"more-dots\"><a href=\"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/2014\/10\/25\/union-intersection-islemleri\/\">[ &#8230; ]<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[157,159,160,161,156,158,155],"class_list":["post-343","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-birlesim","tag-c-intersection","tag-cunion","tag-intersect","tag-intersection","tag-kesisim","tag-union"],"_links":{"self":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=343"}],"version-history":[{"count":1,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"predecessor-version":[{"id":344,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/343\/revisions\/344"}],"wp:attachment":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}