Explain how to sort an array.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 13RQ
icon
Related questions
Question

Explain how to sort an array.

Expert Solution
Step 1

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.

Step 2

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.   

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT