160

# CSE205 Lecture 04

Object-Oriented Programming and Data Structures
Programming with Java III
(202201)

## Javier Gonzalez-SanchezPRO

September 14, 2021

## Transcript

1. jgs
CSE 205
Object-Oriented Programming and
Data Structures
Lecture 04: Programming with Java III
Dr. Javier Gonzalez-Sanchez
[email protected]
javiergs.engineering.asu.edu | javiergs.com
PERALTA 230U
Office Hours: By appointment

2. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 2
jgs
Homework
§ Quiz 03 (1 hour quiz).
Multiple-choice and Open questions

3. jgs
Midterm Exam 3

4. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 4
jgs
Calendar

5. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 5
jgs
Lecture 30
Arrays of Objects
John
Mary Alice
Robert
4 1 3 2

6. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 6
jgs
Lecture 27, 28, 29
Searching
§ Linear Search
§ Binary Search
Sorting
§ Bubble Sort
§ Selection Sort

7. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 7
jgs
Lecture 30
Searching and Sorting Arrays of Objects
John
Mary Alice
Robert
4 1 3 2

8. jgs
Bubble Sort
Code
(

9. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 9
jgs
Bubble sort

10. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 10
jgs
Bubble sort

11. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 11
jgs
Bubble sort

12. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 12
jgs
More Efficient Bubble sort
public static void bubbleSort(int[ ] array1) {
for(int position=array1.length-2; position>=0; position--) {
for (int index=0; index<=position; index++) {
//compare the element at index and at index+1
if (array1[index] > array1[index+1]){
//swap them if they are not in the order
int temp = array1[index+1];
array1[index+1] = array1[index];
array1[index] = temp;
}
}
}
}

13. jgs
Bubble Sort
Code
)

14. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 14
jgs
Lecture 31
2D Array
§ Declaration
§ Initializer List
§ Print values
§ Etc…
0
1
2
3
4
5
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 1 2

15. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 15
jgs
Lecture 32
3D Arrays (Multidimensional)
§ Declaration
§ Initializer List
§ Print values
§ Etc…
12 24
8 16
4 8
9 18
6 12
3 6
6 12
4 8
2 4
3 6
2 4
1 2

16. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 16
jgs
Lecture 33
Recursion
§ How does it work
§ Understand factorial. Fibonacci, Searching, etc.
§ What about print numbers n to m?