8.7 Programming Activity 2: Searching and Sorting Arrays

In this activity, you will work again with a 15-element integer array, performing these activities:

  1. Write a method to perform a Sequential Search of an array.

  2. Write a method to implement the Bubble Sort algorithm to sort an array.

The basic approach to a Bubble Sort is to make multiple passes through the array. In each pass, we compare adjacent elements. If any two adjacent elements are out of order, we put them in order by swapping their values.

To sort an array of n elements in ascending order, Bubble Sort implements a double loop:

  • The outer loop executes n – 1 times.

  • For each iteration of the outer loop, the inner loop steps through all the unsorted elements of the array and does ...

Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.