1 / 13

Review

Review. Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics. 2-D Array and Table. Int [][] e = new int[5][6]. 0. 1. 2. 3. 4. 5. 0. 1. 2. 3. 4. e[3][1]. # of Rows and Columns. int [][] e = new int[5][6]; Get No of rows e.length ?

sema
Download Presentation

Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics

  2. 2-D Array and Table • Int [][] e = new int[5][6] 0 1 2 3 4 5 0 1 2 3 4 e[3][1]

  3. # of Rows and Columns • int [][] e = new int[5][6]; • Get No of rows • e.length ? • Get No of columns • e[0].length ? • e[1].length ?

  4. Print A Matrix Matrix is 2-d Array (rectangular) 1 2 3 4 5 6 7 8 9 print: 1 2 3 4 5 6 7 8 9 public static void Print(int[][] A) { int row = A.length; int col = A[0].length; for (int I=0; I<row; I++) for (int j=0; j<col; j++) System.out.prinln(A[I][j] + “ “); }

  5. Matrix Addition 1 2 3 1 1 1 2 3 4 4 5 6 + 2 2 2 = 6 7 8 4 6 4 3 3 3 7 9 7 A B C formula: Cij = Aij + Bij public static int[][] Add(int[][] A, int[][] B) { }

  6. Matrix Multiplication just for your fun 3 2 2 1 8 5 2 1 + 1 1 = 5 3 formula: Cij = Ai * Bj public static int[][] Multiplication(int[][] A, int[][]B) { }

  7. Sequential or Binary Search Can you perform sequential search on A1? A2? Can you perform binary search on A1? A2? A1: A2:

  8. Summary • Binary search • takes advantage of the characteristics of sorted array, can only be performed on a sorted array. • It’s fast • Sequential search • can be performed on both unsorted and sorted array • It’s slow

  9. Selection Sort: Select the smallest oneDemo: http://www-courses.cs.uiuc.edu/~cs125/cs125/_nav/_framepage/notesPage.html

  10. Insertion Sort: Maintain partial and sorted arrayDemo: http://www-courses.cs.uiuc.edu/~cs125/cs125/_nav/_framepage/notesPage.html

  11. Sort Example • Sort students by height • Sort by height, but female student go first • Sort students by height, if there is a tie, smaller studentID stay in front. • Sort students by name • Sort using insertionsort algorithm

  12. Inheritance • Constructor in child class will call constructor in parent class automatically • method overriding • method overloading

  13. File I/O , GUI • see Kiri’s handout: TextFileInputDemo.java TextFileOutputDemo.java ButtonDemo.java

More Related