| |
Mihai Bâce
mihai.bace@inf.ethz.ch
Oct-19 Mihai Bâce 1
Informatik II Tutorial 3 Mihai Bce mihai.bace@inf.ethz.ch | | - - PowerPoint PPT Presentation
Informatik II Tutorial 3 Mihai Bce mihai.bace@inf.ethz.ch | | Mihai Bce Oct-19 1 Overview Debriefing Exercise 2 Briefing Exercise 3 | | Mihai Bce Oct-19 2 U2.A1 Represent tree with brackets and indented form
| |
Oct-19 Mihai Bâce 1
| | Oct-19 Mihai Bâce 2
| | Oct-19 Mihai Bâce 3
| | Oct-19 Mihai Bâce 4
| | Oct-19 Mihai Bâce 5
| | Oct-19 Mihai Bâce 6
| | Oct-19 Mihai Bâce 7
/** * swaps two fields of {@link RandomArray#numbers} * * @param i a valid index into {@link RandomArray#numbers} * @param j a valid index into {@link RandomArray#numbers} */ private void swap(int i, int j) { int tmp = numbers[j]; numbers[j] = numbers[i]; numbers[i] = tmp; }
| | Oct-19 Mihai Bâce 8
X := X XOR Y Y := X XOR Y X := X XOR Y
| | Oct-19 Mihai Bâce 9
void recursiveSort( int until ) { // 0 elements are considered to be sorted if( until == 0 ) return; // sort first until-1 elements in the array recursiveSort( until – 1 ); // bring the greatest element from the rest to position until-1 for( int i = until; i < a.length; i++ ) { if( a[i] > a[until-1] ){ swap(until-1, i); } } }
| | Oct-19 Mihai Bâce 10
void recursiveSort( int until ) { // 0 elements are considered to be sorted if( until == 0 ) return; // sort first until-1 elements in the array recursiveSort( until – 1 ); // find index of greatest element after until-1 int maxIndex = until - 1; for( int i = until; i < a.length; i++ ) { if( a[i] > a[maxIndex] ) { maxIndex = i; } } // swap elements at maxIndex and until-1 swap( until-1, maxIndex ); }
| | Oct-19 Mihai Bâce 11
while ((e+i)<=14) { if (a[e]> a[e+i]) { e++; i=1; } else i++; }
| | Oct-19 Mihai Bâce 12
x < 10 x < a.length if(myString.compareTo( ”hello world” ) == 0); private static final String REF = ”hello world”; … if(myString.compareTo( REF ) == 0);
| | Oct-19 Mihai Bâce 13
for(int i=0; i < MAX_I; ++i){ nextIterationStep(); } int timeout = 0; while(!userInteraction()){ Thread.yield(); timeout++; }
| | Oct-19 Mihai Bâce 14
if (index >= boundary) return; else if (array[index] == 'x') return; if ( index >= boundary || array[index] == 'x' ) return; if (index < boundary) if (array[index] == 'x') array[index] = '\0'; if ( index < boundary && array[index] == 'x' ) array[index] = '\0'; int counter = 0; while (counter < n) { ... counter++; } for ( int counter = 0; counter < n; counter++) { ... }
| | Oct-19 Mihai Bâce 15
void initialize() { for (int i=0; i<a.length; i++) { Random r = new Random(); a[i] = r.nextInt(1000); } } void initialize() { Random r = new Random(); for (int i=0; i<a.length; i++) { a[i] = r.nextInt(1000); } }
| | Oct-19 Mihai Bâce 16
int leftChild( node ){ return 2 * node + 1; } int rightChild( node ){ return 2 * node + 2; } int father( node ){ return (node – 1) / 2; }
| | Oct-19 Mihai Bâce 17
| | Oct-19 Mihai Bâce 18
| | Oct-19 Mihai Bâce 19
| | Oct-19 Mihai Bâce 20
| | Oct-19 Mihai Bâce 21
Wikipedia: Caesar cipher
| | Oct-19 Mihai Bâce 22
| | Oct-19 Mihai Bâce 23
String myString = "hello"; myString = myString + " world";
StringBuffer myStringBuffer = "hello"; myStringBuffer.append(" world");
Animation by Beat Saurenmann
JAVA String concatenation StringBuffer Method
| | Oct-19 Mihai Bâce 24
Animation von Beat Saurenmann
Garbage Collector
| | Oct-19 Mihai Bâce 25
OR
n
2 1
| | Oct-19 Mihai Bâce 26
| | Oct-19 Mihai Bâce 27
| | Oct-19 Mihai Bâce 28
| | 29
| | Oct-19 Mihai Bâce 30
Image