Explain how to sort an array.
Explain how to sort an array.
![](/static/compass_v2/shared-icons/check-mark.png)
Sort an array: - An array is a collection of the same type of data. In the array, each element is stored in the contiguous location. The array may be sorted or unsorted.
Sorted array means arranging the elements in order either ascending or descending.
To sort an array there are several algorithms such as bubble sort, selection sort, quick sort, merge sort.
Below is the Java program to sort an array using bubble sort technique: -
Explanation: - In the bubble sort technique two adjacent elements are compared by using the if-statement inside the nested loop. If the user wants to sort an array in the ascending order then he should swap the adjacent values (on comparing) if the preceding element is greater than the succeeding element.
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)