Bubblesort Algorithm Implementation in C#, Essays (high school) of Computer science

The implementation of the bubblesort algorithm in c# programming language. The code is presented step by step with comments and a flowchart for better understanding. This resource is ideal for computer science students and developers who want to learn or revise the bubblesort sorting technique.

Typology: Essays (high school)

2017/2018

Uploaded on 03/04/2022

joshua13
joshua13 🇬🇧

11 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Bubblesort Coding in C#
using System;
public class Bubble_Sort
{
public static void Main(string[] args)
{
int[] a = { 3, 0, 2, 5, -1, 4, 1 };
int t;
Console.WriteLine("Original array :");
foreach (int aa in a)
Console.Write(aa + " ");
for (int p = 0; p <= a.Length - 2; p++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine("\n"+"Sorted array :");
foreach (int aa in a)
Console.Write(aa + " ");
Console.Write("\n");
}
}
pf2

Partial preview of the text

Download Bubblesort Algorithm Implementation in C# and more Essays (high school) Computer science in PDF only on Docsity!

Bubblesort Coding in C#

using System; public class Bubble_Sort { public static void Main(string[] args) { int[] a = { 3, 0, 2, 5, -1, 4, 1 }; int t; Console.WriteLine("Original array :"); foreach (int aa in a) Console.Write(aa + " "); for (int p = 0; p <= a.Length - 2; p++) { for (int i = 0; i <= a.Length - 2; i++) { if (a[i] > a[i + 1]) { t = a[i + 1]; a[i + 1] = a[i]; a[i] = t; } } } Console.WriteLine("\n"+"Sorted array :"); foreach (int aa in a) Console.Write(aa + " "); Console.Write("\n"); } }

Flowchart