C
C#11mo ago
Kapa._

✅ Sorted Array not Printing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A_C_Assignment
{
internal class BubbleSort
{
public static void BubbleAscend(int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

Console.ReadKey();
}

public static void BubbleDescend(int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (arr[j] < arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A_C_Assignment
{
internal class BubbleSort
{
public static void BubbleAscend(int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

Console.ReadKey();
}

public static void BubbleDescend(int[] arr)
{
int n = arr.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (arr[j] < arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

Console.ReadKey();
}
}
}
24 Replies
Kapa._
Kapa._OP11mo ago
Program Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace A_C_Assignment
{
internal class Program
{
static void Main(string[] args)
{
int[] numbers = { 32867, 8350, 26107, 21308, 8903, 23685, 35401, 36996, 20817, 8485,
31746, 26009, 9002, 8048, 24150, 669, 34754, 20947, 17380, 4524,
14095, 29499, 8856, 21632, 30410, 8265, 29626, 5523, 2195, 12641,
36807, 27758, 11452, 23913, 13129, 7322, 11244, 32139, 4689, 18853,
31937, 39167, 2868, 17662, 16683, 9441, 34607, 36610, 31672, 32951,
38041, 16056, 22680, 18912, 28401, 13096, 9657, 21236, 10431, 39694,
17104, 20165, 14309, 14017, 2973, 20049, 24675, 30573, 38300, 4135,
16483, 4053, rest of the numbers...

Console.WriteLine("Ascending: ");
BubbleSort.BubbleAscend(numbers);
Console.WriteLine(string.Join(",", numbers));


Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace A_C_Assignment
{
internal class Program
{
static void Main(string[] args)
{
int[] numbers = { 32867, 8350, 26107, 21308, 8903, 23685, 35401, 36996, 20817, 8485,
31746, 26009, 9002, 8048, 24150, 669, 34754, 20947, 17380, 4524,
14095, 29499, 8856, 21632, 30410, 8265, 29626, 5523, 2195, 12641,
36807, 27758, 11452, 23913, 13129, 7322, 11244, 32139, 4689, 18853,
31937, 39167, 2868, 17662, 16683, 9441, 34607, 36610, 31672, 32951,
38041, 16056, 22680, 18912, 28401, 13096, 9657, 21236, 10431, 39694,
17104, 20165, 14309, 14017, 2973, 20049, 24675, 30573, 38300, 4135,
16483, 4053, rest of the numbers...

Console.WriteLine("Ascending: ");
BubbleSort.BubbleAscend(numbers);
Console.WriteLine(string.Join(",", numbers));


Console.ReadKey();
}
}
}
Buddy
Buddy11mo ago
$refvsvalue
Kapa._
Kapa._OP11mo ago
could you please explain?
Buddy
Buddy11mo ago
My mistake, it is passed as reference already because it is an array.
Kapa._
Kapa._OP11mo ago
is it not modified by the bubblesort.bubbleascend? in the sorting class correct?
Buddy
Buddy11mo ago
Try it and see
Kapa._
Kapa._OP11mo ago
oki
SparkyCracked
SparkyCracked11mo ago
How do we run c# code using the bot?
Buddy
Buddy11mo ago
!e code here
Kapa._
Kapa._OP11mo ago
code is still only printing the word "ascending"
Buddy
Buddy11mo ago
Will you please check if you have any errors?
Kapa._
Kapa._OP11mo ago
vs says no issues found
Buddy
Buddy11mo ago
Visual studio has a stupid feature that runs old build if current one fails to build.
Kapa._
Kapa._OP11mo ago
ive ran it twice still no problems wait i found the problem
Buddy
Buddy11mo ago
Great!
Kapa._
Kapa._OP11mo ago
the problem was i had Console.ReadKey(); in the sorting algorithm runs without ref aswell ty for the help brother
MODiX
MODiX11mo ago
Buddy
My mistake, it is passed as reference already because it is an array.
Quoted by
<@203166497198047232> from #Sorted Array not Printing (click here)
React with ❌ to remove this embed.
Buddy
Buddy11mo ago
Arrays are reference types, so you don't need to pass it as ref
Kapa._
Kapa._OP11mo ago
sweet ty how do i close the post?
Buddy
Buddy11mo ago
$close
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Buddy
Buddy11mo ago
Just type /close 🙂
Kapa._
Kapa._OP11mo ago
tyty

Did you find this page helpful?