-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
27 lines (25 loc) · 823 Bytes
/
Program.cs
File metadata and controls
27 lines (25 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
Author: Ramya Kosaraju
Date: 2/28/2024
Comments: This C# Console Application code demonstrates the
Bubble Sort Algorithm. No input
is required for the script. It will execute without
input against two pre-populated arrays.
*/
using System;
int[] array = { 3, 62, 5, 16, 4, 10 }; //input array
Console.WriteLine("Original array: " + string.Join(", ", array)); //printing of input array
// Bubble Sort
for (int i = 0; i < array.Length - 1; i++)
{
for (int j = 0; j < array.Length - 1 - i; j++)
{
if (array[j] > array[j + 1]) //comparing numbers
{
// Swapping of numbers
(array[j], array[j + 1]) = (array[j + 1], array[j]);
}
}
}
//output is getting printed using below line of code
Console.WriteLine("Sorted array: " + string.Join(", ", array));