{"id":66939,"date":"2022-03-05T08:00:01","date_gmt":"2022-03-05T07:00:01","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=66939"},"modified":"2022-06-05T13:41:01","modified_gmt":"2022-06-05T11:41:01","slug":"csharp-bubble-sort","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-bubble-sort\/","title":{"rendered":"Bubble Sort In C#"},"content":{"rendered":"<p>Sorting arrays is quite a common problem in programming. The bubble sort algorithm is simple to implement as it involves comparing adjacent elements and swapping them when they are in the wrong order. We are going to learn how Bubble Sort in C# works.\u00a0<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-algorithms\/BubbleSort\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s dive in.\u00a0<\/p>\n<h2><a id=\"time-complexity\"><\/a>What is Bubble Sort Algorithm?<\/h2>\n<p>So, how does bubble sort in C# work?<\/p>\n<p>Let&#8217;s say we want to sort an array that has seven elements:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] array = { 73, 57, 49, 99, 133, 20, 1 };<\/code><\/p>\n<p>Using the bubble sort algorithm, let&#8217;s start by comparing 73 and 57. 57 is less than 73, so we swap their positions and the array becomes:<\/p>\n<p><code><span style=\"color: #ff0000;\">57<\/span>, <span style=\"color: #0000ff;\">73<\/span>, 49, 99, 133, 20, 1<\/code><\/p>\n<p>49 is less than 73, which triggers the algorithm to swap their positions:<\/p>\n<p><code>57, <span style=\"color: #ff0000;\">49<\/span>, <span style=\"color: #0000ff;\">73<\/span>, 99, 133, 20, 1<\/code><\/p>\n<p>73 is less than 99 while 99 is less than 133, so the algorithm skips these positions. Next, we compare 133 with 20 and swap their positions as 20 is less than 133:<\/p>\n<p><code>57, 49, 73, 99, <span style=\"color: #ff0000;\">20<\/span>, <span style=\"color: #0000ff;\">133<\/span>, 1<\/code><\/p>\n<p>Since 1 is less than 33, the algorithm swaps their positions:<\/p>\n<p><code>57, 49, 73, 99, 20, <span style=\"color: #ff0000;\">1<\/span>, <span style=\"color: #0000ff;\">133<\/span><\/code><\/p>\n<p>The bubble sort algorithm repeats this process until all the elements are in the correct order with the final result being:<\/p>\n<p><code>1, 20, 49, 57, 73, 99, 133\u00a0<\/code><\/p>\n<h2><a id=\"implementation\"><\/a>How to Implement Bubble Sort in C#?<\/h2>\n<p>We are going to define an integer array property <code>NumArray<\/code>, that we are going to use to implement the bubble sort algorithm:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public int[]? NumArray { get; set; }<\/code><\/p>\n<p>Let&#8217;s create a method that implements the bubble sort algorithm in C# that sorts the values in the <code>NumArray<\/code> property:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public int[] SortArray() \r\n{\r\n    var n = NumArray.Length;\r\n\r\n    for (int i = 0; i &lt; n - 1; i++)\r\n        for (int j = 0; j &lt; n - i - 1; j++)\r\n            if (NumArray[j] &gt; NumArray[j + 1])\r\n            {\r\n                var tempVar = NumArray[j];\r\n                NumArray[j] = NumArray[j + 1];\r\n                NumArray[j + 1] = tempVar;\r\n            }\r\n\r\n    return NumArray;\r\n}<\/pre>\n<p>The variable <code>n<\/code> holds the size of the array while the <code>tempVar<\/code> variable holds values temporarily during the swap process. Let&#8217;s use our array example to understand how the code works:<\/p>\n<p>The outer loop iterates through the array while the inner loop compares adjacent elements. Since 57 is less than 73, they swap their positions and the inner loop continues comparing adjacent values until it gets to the last element of that array. For each iteration of the outer loop, the inner loop iterates while performing comparisons.<\/p>\n<p>Let&#8217;s check if our loop performed correctly:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var array = new int[] { 73, 57, 49, 99, 133, 20, 1 };\r\nvar expected = new int[] { 1, 20, 49, 57, 73, 99, 133 };\r\nvar sortFunction = new Bubble();\r\nsortFunction.NumArray = array;\r\n\r\nvar sortedArray = sortFunction.SortArray();\r\n\r\nAssert.IsNotNull(sortedArray);\r\nCollectionAssert.AreEqual(sortedArray, expected);<\/pre>\n<h2><a id=\"algorithm-complexity\"><\/a>Time and Space Complexity<\/h2>\n<p>The space complexity of the bubble sort algorithm is O(1) because it requires a single additional space that holds the temporary value we are using to swap the elements.\u00a0<\/p>\n<p>Nested loops have detrimental effects on how algorithms perform as the size of the array grows. The bubble sort algorithm has a time complexity of O(N\u00b2) as it has two nested loops. Let&#8217;s analyze how the algorithm performs in different levels of complexity.<\/p>\n<p><strong>Best Case Complexity: <\/strong>this case occurs when we want to sort an array that is already in required order. The algorithm traverses the array without swapping values, which means, its complexity is O(N).\u00a0<\/p>\n<p><strong>Average Case Complexity: <\/strong>this case occurs when an array has some elements that are in the correct order. The bubble sort algorithm performs comparisons while swapping some values, which means, it has a complexity of O(N\u00b2).\u00a0<\/p>\n<p><strong>Worst Case Complexity: <\/strong>this scenario occurs when assuming we have a list of numbers that are in descending order and we need to sort them in ascending order, the algorithm would encounter a worst-case complexity as the length of that array grows to N. Therefore, the algorithm compares all elements while swapping them, which means, it has a complexity of O(N\u00b2).\u00a0<\/p>\n<h2><a id=\"benefits\"><\/a>Advantages and Disadvantages<\/h2>\n<p>The bubble sort algorithm is easy to learn and implement. On top of that, it has little memory overhead as the sorting is done in place, which is similar to <a href=\"https:\/\/code-maze.com\/csharp-selection-sort\/\" target=\"_blank\" rel=\"nofollow noopener\">selection sort<\/a>. This attribute comes in handy in memory-intensive applications. This algorithm <strong>performs well in cases where an array is almost in order as it is an example of the <\/strong><a href=\"#algorithm-complexity\">best case complexity<\/a><strong> scenario<\/strong>.\u00a0<\/p>\n<p>On the other hand, the bubble sort algorithm <strong>has high levels of time complexity O(N\u00b2), which is inefficient when compared to other algorithms<\/strong> such as merge sort.\u00a0<\/p>\n<h2><a id=\"optimization\"><\/a>How to Optimize the Bubble Sort Algorithm in C#?<\/h2>\n<p>We can see that the bubble sort algorithm still iterates even in cases where an array is already in order. We can optimize the swapping process by checking whether we need to swap elements or not. Let&#8217;s optimize our previous implementation and see what&#8217;s different about it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public int[] SortOptimizedArray()\r\n{\r\n    var n = NumArray.Length;\r\n    bool swapRequired;\r\n\r\n    for (int i = 0; i &lt; n - 1; i++) \r\n    {\r\n        swapRequired = false;\r\n\r\n        for (int j = 0; j &lt; n - i - 1; j++)\r\n            if (NumArray[j] &gt; NumArray[j + 1])\r\n            {\r\n                var tempVar = NumArray[j];\r\n                NumArray[j] = NumArray[j + 1];\r\n                NumArray[j + 1] = tempVar;\r\n                swapRequired = true;\r\n            }\r\n        if (swapRequired == false)\r\n            break;\r\n    }\r\n\r\n    return NumArray;\r\n}<\/pre>\n<p>We introduce a boolean value <code>swapRequired<\/code> to track whether we need to swap the elements or not. The <code>swapRequired<\/code> variable becomes true when we swap elements, otherwise, it&#8217;s set to false. In iterations where swapping is not required, the <code>swapRequired<\/code> will be false, which means, the array elements are in order and we break the loop before it finishes to the end.\u00a0 This way we save a lot of time.<\/p>\n<p>Let&#8217;s check if our optimal bubble sort algorithm performs correctly:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var array = new int[] { 73, 57, 49, 99, 133, 20, 1 };\r\nvar expected = new int[] { 1, 20, 49, 57, 73, 99, 133 };\r\nvar sortFunction = new Bubble();\r\n\r\nsortFunction.NumArray = array;\r\nvar sortedArray = sortFunction.SortOptimizedArray();\r\n\r\nAssert.IsNotNull(sortedArray);\r\nCollectionAssert.AreEqual(sortedArray, expected);<\/pre>\n<h2><a id=\"performance\"><\/a>Bubble Sort Performance<\/h2>\n<p>Let&#8217;s verify the bubble sort algorithm has a time complexity of O(N\u00b2) by measuring the time it takes for the algorithm to sort an array.<\/p>\n<p>First, let&#8217;s write a method to generate a set of random numbers that are going to be added into the array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static int[] GenerateRandomNumber(int size)\r\n{\r\n    var array = new int[size];\r\n    var rand = new Random();\r\n    var maxNum = 10000;\r\n\r\n    for (int i = 0; i &lt; size; i++)\r\n        array[i] = rand.Next(maxNum + 1);\r\n\r\n    return array;\r\n}<\/pre>\n<p>The <code>GenerateRandomNumber<\/code> method takes an integer as its sole input. Using the inbuilt <code>Random<\/code> class, we generate integer values (less than 10000) that we&#8217;re going to put into the array.<\/p>\n<p>To simulate a scenario where we have a sorted array, we are going to define a method that generates a sequence of elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static int[] GenerateSortedNumber(int size)\r\n{\r\n    var array = new int[size];\r\n\r\n    for (int i = 0; i &lt; size; i++)\r\n        array[i] = i;\r\n\r\n    return array;\r\n}<\/pre>\n<p class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Next, we are going to implement a performance benchmark to assess how the normal bubble sort algorithm performs versus the optimized bubble sort algorithm when sorting randomly generated numbers:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] smallArray = GenerateRandomNumber(200);\r\nint[] mediumArray = GenerateRandomNumber(2000);\r\nint[] largeArray = GenerateRandomNumber(200000);<\/pre>\n<p>The array objects have different sizes (to simulate time complexity scenarios) and hold <a href=\"https:\/\/code-maze.com\/csharp-generate-random-numbers-range\/\" target=\"_blank\" rel=\"noopener\">random numbers<\/a> that are added by the <code>GenerateRandomNumber<\/code> method. Let&#8217;s assess the sample best, average, and worst-case complexity performance results of the algorithm:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|             Method |      NumArray |                Mean |             Error |              StdDev |\r\n|------------------- |-------------- |--------------------:|------------------:|--------------------:|\r\n|          SortArray | Int32[200000] | 34,217,602,373.3 ns | 680,856,233.76 ns | 1,852,319,597.83 ns |\r\n| SortOptimizedArray | Int32[200000] |        404,684.5 ns |      22,163.41 ns |        64,300.07 ns | \r\n|          SortArray |   Int32[2000] |      3,188,246.8 ns |      32,947.14 ns |        30,818.77 ns |\r\n| SortOptimizedArray |   Int32[2000] |          3,191.4 ns |          23.51 ns |            21.99 ns | \r\n|          SortArray |    Int32[200] |         32,333.2 ns |         512.23 ns |           766.68 ns |\r\n| SortOptimizedArray |    Int32[200] |            323.9 ns |           6.34 ns |             6.51 ns |<\/pre>\n<p>The worst-case execution demonstrates this concept as the <code>SortArray<\/code> method takes approximately 34,217,602,373.3 ns (~34.21 seconds) to run while the <code>SortOptimizedArray<\/code> method takes 404,684.5 ns (~0.000404 seconds) which is a huge difference.<\/p>\n<p>Next, are going to re-run the same benchmark but with the arrays holding values that have already been sorted invoking the <code>GenerateSortedNumber<\/code> method. These are the array objects we are going to use for the next benchmark run:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] sortedSmallArray = GenerateSortedNumber(200);\r\nint[] sortedMediumArray = GenerateSortedNumber(2000);\r\nint[] sortedLargeArray = GenerateSortedNumber(200000);<\/pre>\n<p>And let&#8217;s assess the results of this benchmark:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|             Method |      NumArray |                Mean |             Error |              StdDev |\r\n|------------------- |-------------- |--------------------:|------------------:|--------------------:|\r\n|          SortArray | Int32[200000] | 33,916,006,053.2 ns | 654,826,121.87 ns | 1,277,188,059.76 ns |\r\n| SortOptimizedArray | Int32[200000] |        320,074.5 ns |       6,279.92 ns |        10,663.78 ns |\r\n|          SortArray |   Int32[2000] |      3,122,602.4 ns |      16,882.03 ns |        15,791.46 ns |\r\n| SortOptimizedArray |   Int32[2000] |          3,112.0 ns |          18.00 ns |            15.95 ns |\r\n|          SortArray |    Int32[200] |         34,262.8 ns |       1,023.35 ns |         2,919.67 ns |\r\n| SortOptimizedArray |    Int32[200] |            315.0 ns |           3.85 ns |             3.22 ns |<\/pre>\n<p>The optimized bubble sort algorithm implementation is faster than the normal version of the bubble sort algorithm in all case scenarios. We can also see that the time complexity of this algorithm worsens exponentially as the number of elements increases.<\/p>\n<p>We can also see that the algorithm takes less time for an array that is already in order from the second benchmark which means that the complexity is lower. This would be even more emphasized with the larger arrays.<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>In this article, we&#8217;ve learned how the bubble sort in C# works and how to implement it. It is simple to implement but not that efficient when compared to other algorithms. In case you want to learn how to implement another sorting algorithm, check out this <a href=\"https:\/\/code-maze.com\/csharp-selection-sort\/\" target=\"_blank\" rel=\"nofollow noopener\">selection sort<\/a>\u00a0article.\u00a0<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorting arrays is quite a common problem in programming. The bubble sort algorithm is simple to implement as it involves comparing adjacent elements and swapping them when they are in the wrong order. We are going to learn how Bubble Sort in C# works.\u00a0 Let&#8217;s dive in.\u00a0 What is Bubble Sort Algorithm? So, how does [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1010,12],"tags":[1108,1109,1110],"class_list":["post-66939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm","category-csharp","tag-bubble-sort","tag-bubble-sort-algorithm","tag-bubble-sort-c","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Bubble Sort In C# - Code Maze<\/title>\n<meta name=\"description\" content=\"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-bubble-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bubble Sort In C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-bubble-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-05T07:00:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-05T11:41:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Bubble Sort In C#\",\"datePublished\":\"2022-03-05T07:00:01+00:00\",\"dateModified\":\"2022-06-05T11:41:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/\"},\"wordCount\":1138,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"bubble sort\",\"bubble sort algorithm\",\"bubble sort c#\"],\"articleSection\":[\"Algorithm\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-bubble-sort\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/\",\"url\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/\",\"name\":\"Bubble Sort In C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-03-05T07:00:01+00:00\",\"dateModified\":\"2022-06-05T11:41:01+00:00\",\"description\":\"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-bubble-sort\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-bubble-sort\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bubble Sort In C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bubble Sort In C# - Code Maze","description":"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.","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":"https:\/\/code-maze.com\/csharp-bubble-sort\/","og_locale":"en_US","og_type":"article","og_title":"Bubble Sort In C# - Code Maze","og_description":"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.","og_url":"https:\/\/code-maze.com\/csharp-bubble-sort\/","og_site_name":"Code Maze","article_published_time":"2022-03-05T07:00:01+00:00","article_modified_time":"2022-06-05T11:41:01+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Bubble Sort In C#","datePublished":"2022-03-05T07:00:01+00:00","dateModified":"2022-06-05T11:41:01+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/"},"wordCount":1138,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["bubble sort","bubble sort algorithm","bubble sort c#"],"articleSection":["Algorithm","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-bubble-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/","url":"https:\/\/code-maze.com\/csharp-bubble-sort\/","name":"Bubble Sort In C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-03-05T07:00:01+00:00","dateModified":"2022-06-05T11:41:01+00:00","description":"Bubble Sort in C# is one of the most common sorting algorithms used. In this article we implement our own version of Bubble Sort in C#.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-bubble-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-bubble-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Bubble Sort In C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=66939"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66939\/revisions"}],"predecessor-version":[{"id":66976,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66939\/revisions\/66976"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=66939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=66939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=66939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}