{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Linear Data Structures 1.3

# Linear Data Structures 1.3 - System.out.println(“ Snow...

This preview shows pages 1–5. Sign up to view the full content.

Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 11 - Example Example [ 2D array of objects in Java = an array of arrays of references] Square[][] board = new Square[2][3];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 12 - Arrays in Java Useful Built-In Methods in Java.util.Arrays equals (A,B) • returns true if A and B have an equal number of elements and every corresponding pair of elements in the two arrays are equal fill (A,x) • store element x into every cell of array A sort (A) • sort the array A in the natural ordering of its elements binarySearch ([int] A, int key) • search the specified array of sorted ints for the specified value using the binary search algorithm The Java.util.Arrays Class
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 13 - Example What is printed? int [] A={12, 24, 37, 53, 67}; int [] B=A.clone(); if (A==B) System.out.println(“ Superman ”); if (A.equals(B))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println(“ Snow White ”); Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 14 - Limitations of Arrays • Static data structure – size must be fixed at the time the program creates the array – once set, array size cannot be changed – if number of entered items > declared array size ˰ out of memory • fix 1: use array size > number of expected items ˰ waste of memory • fix 2: increase array size to fit the number of items ˰ extra time • Insertion / deletion in an array is time consuming – all the elements following the inserted element must be shifted appropriately • Example [ time complexity of “growing” an array] if (numberOfItems > numbers.length) { int newNumbers = new int [2*numbers.length]; System.arraycopy(numbers, 0, newNumbers, 0, numbers.length); numbers = newNumbers; } Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 15 - Array Lists Chapter 6.1...
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

Linear Data Structures 1.3 - System.out.println(“ Snow...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online