Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented By: Mahmoud Rafeek Alfarra

Similar presentations


Presentation on theme: "Presented By: Mahmoud Rafeek Alfarra"— Presentation transcript:

1 Presented By: Mahmoud Rafeek Alfarra
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Data structure Using C# Information Technology , 3’rd Semester Lecture 3 : Insert and delete elements from array Presented By: Mahmoud Rafeek Alfarra

2 Outline Array data structure Emank X Mezank !! Inserting element
Into unsorted array Into sorted array Deleting element Emank X Mezank !!

3 Inserting element Into unsorted array
Inserting element into array with out affecting the values of the elements’ array. This task demand the shifting of values from the particular cell … Presented & Prepared by: Mahmoud R. Alfarra

4 Inserting element Into unsorted array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 77 7 9 8 55 56 10 79 80 81 45 90 99 Into 7’th cell 12 1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 77 7 9 8 55 12 56 10 79 80 81 45 90 99 Presented & Prepared by: Mahmoud R. Alfarra

5 Inserting element Into unsorted array
for ( int i = arrayLength- 1; i >wanted; i-- ) b[ i- 1 ] = b[ i ] b[wanted] = inserted HW 3.1 Write a method that performs inserting element into unsorted array Presented & Prepared by: Mahmoud R. Alfarra

6 Inserting element Into sorted array
To Insert a new elements in a sorted array, we must: Detect the cell’s index of the inserted element. Shifting the elements to the particular side. Presented & Prepared by: Mahmoud R. Alfarra

7 Inserting element Into a sorted array
7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 7 9 12 15 23 30 45 70 77 80 88 90 99 To insert value 13 1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 7 9 12 13 15 23 30 45 70 77 80 88 90 99 Presented & Prepared by: Mahmoud R. Alfarra

8 Inserting element Into a sorted array
8 Detect the cell’s index of the inserted element for ( int i = 0 ; i < arraylength; i++ ) if ( array[i]> inserted ) index = i break HW 3.2 Write a method that performs the searching about the particular index Presented & Prepared by: Mahmoud R. Alfarra

9 Inserting element Into a sorted array
9 Shifting the elements to the particular side. for ( int i = arrayLength- 1; i >index ; i-- ) b[ i- 1 ] = b[ i ] b [index] = inserted HW 3.3 Write a method that performs inserting element into unsorted array Presented & Prepared by: Mahmoud R. Alfarra

10 Deleting an element from array
10 We have two ways to delete an element from array: Delete with its index. (cell number 5) Delete with its value. (cell of value 20) Presented & Prepared by: Mahmoud R. Alfarra

11 deleting element from an array
11 Delete cell with its index 1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 7 9 12 15 23 30 45 70 77 80 88 90 99 To delete the 5’th cell 15 2 7 80 88 90 99 9 12 15 23 30 45 77 1 3 4 5 6 8 10 11 13 array 14 array 2 7 80 88 90 99 9 12 23 30 45 15 77 1 3 4 5 6 8 10 11 13 14 Null Presented & Prepared by: Mahmoud R. Alfarra

12 deleting element from an array
12 Delete cell with its index for ( int i = index ; i < arraylength-1; i++ ) array [i] = array[i+1] Array [arraylength-1] = null HW 3.4 Delete cell with its index Presented & Prepared by: Mahmoud R. Alfarra

13 deleting element from an array
13 Delete cell with its value 1 2 3 4 5 6 7 8 9 10 11 12 13 14 array 2 7 9 12 15 23 30 45 15 77 80 88 90 99 To delete the first cell with value 15 2 7 80 88 90 99 9 12 15 23 30 45 77 1 3 4 5 6 8 10 11 13 array 14 array 2 7 80 88 90 99 9 12 23 30 45 15 77 1 3 4 5 6 8 10 11 13 14 Null Presented & Prepared by: Mahmoud R. Alfarra

14 deleting element from an array
14 Delete cell with its value for ( int i = 0 ; i < arraylength-1; i++ ) if (array [i] = value) Index = I break Implement the delete cell with its index HW 3.5 Implement a method to find the wanted cell Presented & Prepared by: Mahmoud R. Alfarra

15 deleting element from an array
15 Delete cell with its value || for ( int i = index ; i < arraylength-1; i++ ) array [i] = array[i+1] Array [arraylength-1] = null HW 3.6 Implement an application to delete cell with value 100 Presented & Prepared by: Mahmoud R. Alfarra

16 Emank X Mezank !! k

17 Multiple-Subscripted Arrays & Advanced Practices
Next Lecture Multiple-Subscripted Arrays & Advanced Practices


Download ppt "Presented By: Mahmoud Rafeek Alfarra"

Similar presentations


Ads by Google