Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Reply
what outer loop and inner loop represent in bubble sort
ahmed salah
Dec 22 2016 6:13 PM
307
Reply
Hi i work in visual studio 2015 c# console applications .
I try to make bubble sort to array unsorted but i cannot do that
i search for internet about that i understand idea .
it is make comparison between small and largest then swap items to make in order array
but i cannot understand this code .
so that what outer loop represent and inner loop represent ?
red lines for outer loop and inner loop
/*
* C# Program to Perform Bubble Sort
*/
using
System;
class
bubblesort
{
static
void
Main(
string
[] args)
{
int
[] a = { 30, 20, 50, 40, 10 };
int
t;
Console.WriteLine(
"The Array is : "
);
for
(
int
i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
for
(
int
j = 0; j <= a.Length - 2; j++)
outer loop
{
for
(
int
i = 0; i <= a.Length - 2; i++)
inner loop
{
if
(a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine(
"The Sorted Array :"
);
foreach
(
int
aray
in
a)
Console.Write(aray +
" "
);
Console.ReadLine();
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
error - add list items to the static class variable C#
How can I Decryption This HashSha256 algorithm?