My intent for this article is to explain how to answer a question that is often asked in an interview, which is: Write a programme that does a Bubble Sort using C#. A candidate new to the interview can become totally confused because the first problem is that the candidate does not know what a bubble sort is.
So, considering the preceding requirement and numerous emails sent to me from beginners, I have decided to write this article with the basics and especially focus on the beginner, student, or whoever might face this type of question in an interview.
So let us start with the basics.
What is a Sorting?
Sorting means arranging the items (numbers, etc.) in a specified manner, in other words, ascending or descending, etc.
To change the position of numbers or other items from right to left, left to right, or any position as you wish. In other words, changing an unordered sequence into an ordered sequence is called a "Bubble Sort."
Suppose I have the given input as:
Then the given numbers after the Bubble Sort are :
Now that we completely understand what is meant by "bubble sorting," next I will explain how to do it step-by-step, as in the following:
- Open Visual Studio from Start - All programs - Microsoft Visual Studio.
- Then go to to "File" - "New" - "Project..." then select Visual C# - Windows - Console application.
- After that specify the name such as Bubble Sort or whatever name you wish and the location of the project and click on the "OK" button. The new project is created.