Linear Data Structures 1.3

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

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

View Full Document Right Arrow Icon
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];
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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))
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
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

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online