danuz

Hi,

I made one code which sorts numbers from the smallest to the biggest.
Can anyone please write comments in my code what exactly an individual pseudo-code do ?
I'm very confused about that pseudo-codes and don't exactly know what are arrays's functions in that code.

The code is:

``````int i, j, k;

int[] a = new int[10];

for (i = 0; i < 10; i++)
{
Console.Write("Enter the number:", i);
a[i] = int.Parse(Console.ReadLine());

if (a[i] == 0)
break;
}
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
{
if (a[i] > a[j])
{
k = a[i];
a[i] = a[j];
a[j] = k;
}
}
}
Console.WriteLine("------------------------------------------------------");
Console.WriteLine("Show sorted numbers from the smallest to the biggest :");
Console.WriteLine("------------------------------------------------------");
for (i = 0; i < 10; i++)
{
Console.WriteLine("{0}. Number = {1}", i, a[i]);
}
Console.ReadLine();``````

I would be very thankful if someone can help me with that.

danuz

hirushan

you can use :

``````Array.Sort(a);
Array.Reverse(a);``````

methods to Sort arrays

danuz

Yes but I already sent this code to assistent. Today I have defense about this code and I need to know exactly what is this code doing at an invidual pseudo-code. That's why I need good comments.

divin757 8

did you make a bubble sort lol. there are a lot of better methods for sorting. what you did was go through your array a bunch of times checking if a number is bigger that the other and if it is you switch. this is highly inefficient because you may move a number from one end of the array to the other stopping at every node.

danuz

Yes its not a good way of code, but I need to explain to assistent it anyway xD

iconoclazt 11

Yes its not a good way of code, but I need to explain to assistent it anyway xD

Array.Sort() sorts the elements in an entire one-dimensional Array using the IComparable interface implemented by each element of the Array. Straight from MSDN.

ddanbe 2,720

Line 20: the k variable is also called a temporary used to swap two other variables.