MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE DATA STRUCTURE Information Technology , 3’rd Semester Using C# Lecture 4: Multiple-Subscripted Arrays & Advanced Practices about array data structure Presented By: Mahmoud Rafeek Alfarra Outline Multiple-Subscripted Arrays data structure Sorting Searching Inserting Deleting Advanced practices Emank X Mezank !! Multiple-Subscripted Arrays 3 Such arrays require two or more subscripts to identify particular elements. Presented & Prepared by: Mahmoud R. Alfarra Sorting 4 0 1 2 77 2 7 3 9 4 8 0 1 55 12 56 10 79 2 80 81 45 90 99 3 89 87 55 4 78 Sorting Multiple-Subscripted Arrays can be done on rows or columns By row: must fix row index and increment the column index. By column: must fix col. index and increment the row index. Presented & Prepared by: Mahmoud R. Alfarra Sorting Multiple-Subscripted Arrays By row 5 Row = 0; for ( int pass = 1, pass < colLength, pass++ ) for ( int col = 0; col < colLength- 1; i++ ) if ( b[Row][col] > b[Row][ i + 1 ] ) Swap( b[Row][col], b[Row][ i + 1 ] ); HW 4.1 Write a method that performs sorting multiplesubscripted arrays by row and by col. Presented & Prepared by: Mahmoud R. Alfarra Searching in Multiple-Subscripted Arrays 6 for ( int row = 0, row < rowLength-1, row++ ) for ( int col = 0; col < colLength- 1; col++ ) if ( b[row][col] == wanted ) flagr=row; Flagc= col; Break; HW 4.2 Write a method that performs searching multiplesubscripted arrays. Presented & Prepared by: Mahmoud R. Alfarra Inserting element Into Multiple-Subscripted Arrays 7 To Insert a new elements in an unsorted array, we must Shift the elements to the particular side. With fix the row or column index Presented & Prepared by: Mahmoud R. Alfarra Deleting element from Multiple-Subscripted Arrays 8 To delete an element from an array, we must overwrite the specific element. With fix the row or column index Presented & Prepared by: Mahmoud R. Alfarra Advanced practices 9 1. Use a single-subscripted array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the “worst case” (in which all 20 numbers are different). Use the smallest possible array to solve this problem. Presented & Prepared by: Mahmoud R. Alfarra Advanced practices 10 2. Use a single-subscripted array to solve the following problem: Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, insert it into the particular cell as sorted as and if it is duplicated reject it. Presented & Prepared by: Mahmoud R. Alfarra Advanced practices 11 3. Use a single-subscripted array to solve the following problem: insert 20 integer numbers. Then delete all the duplicated numbers Presented & Prepared by: Mahmoud R. Alfarra !! Emank X Mezank يقـول اهلل تعالى: يوم تكون الجبــال كالعهن المنفـوش Next Lecture Recursion