Programming with Java III Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
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; } } } }
Lecture 33 Recursion § How does it work § Understand factorial. Fibonacci, Searching, etc. § What about print numbers n to m? § What about add numbers 0 to n?
Ph.D. [email protected] Spring 2022 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.