100 likes | 267 Views
Sorting and Searching Arrays. Partially Filled Arrays. Not all elements of the array might receive values: This is termed a partially filled array. Programmer must keep track of how much of array is used.
E N D
Partially Filled Arrays • Not all elements of the array might receive values: • This is termed a partially filled array. • Programmer must keep track of how much of array is used.
Consider arranging elements of an array so that they have an ascending order. • Algorithm is to step through the array: • Place the smallest element in index 0. • Swap elements as needed to sort the entire array.
This method sorts the array This method searches for the next smallest element
“selectionSort (arg)” is a static method ClassName . staticMethodName (arg)
MultidimensionalArray we can access elements of the table with a nested“for” loop
column 0 1 2 3 4 5 5 5.5 6 6.5 7 7.5 declaring a 2-dimentional array year 1 2 3 4 5 6 7 8 9 10 computing the contents of the array printing the contents of the array
using System.out.println(…); using 2 “for” loops and System.out.println(…);