TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vanessa lemme
NA
7
807
basic bubble sort
Jun 10 2017 7:52 PM
I have an array of 10 elements which makes nine comparisons but i want it to make eight comparisons on the second pass and seven on the third pass etc. Can anyone help please?
private static int[] arr = {17, 3, 9, 15, 7, 32, 21, 99, 10, 5};
{
static void Main(string[] args)
{
Console.WriteLine("Before Sorting: \n");
foreach (int i in arr)
{
Console.Write(i + " ");
}
Console.WriteLine();
BubbleSort();
Console.ReadKey();
}
public static void BubbleSort()
{
int temp;
Console.WriteLine("\nAfter Bubble Sorting: ");
for (int i = 0; i < arr.Length; i++)
{
for (int j = 0; j < arr.Length - 1; j++)
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
Console.WriteLine();
foreach (int q in arr)
{
Console.Write(q + " ");
}
}
}
}
}
Reply
Answers (
2
)
Finding out square root of any number?
how to find the typing accuracy of user in c# and save it