Lec c5 - 1 Computer Programming I TA C162 . Todays Agenda...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Computer Programming I TA C162 . Todays Agenda Inserting an element in an Array. Deleting an element from an Array. Sorting a list of numbers (Insertion Sort) . Finding maximum and minimum element in an Array. Sorting a list of numbers (Selection Sort ). 2 Computer Programming I TA C162 . Example: Inserting an element at specified index in an Array. int main (void) { int arr[100]; int element, index, i; printf ("Enter the new element and index"); scanf("%d %d",&element, &index); // Assume that array elements are initialized. for (i=99 ; i>index ; i--) // Shift the elements arr[i] = arr[i-1]; arr[index] = element; } Q. How to delete an element at specified location ?? 3 Computer Programming I TA C162 . Sorting 4 Computer Programming I TA C162 . Sorting Input: A sequence of n numbers a 1 , , a n Output: A reordering a 1 , , a n , such that a 1 < < a n 14 3 2 6 8 16 2 3 14 16 6 8 5 Computer Programming I TA C162 . Sorting Big idea: Inserting an element into a sorted list in the appropriate position retains the order. So what? Start with a singleton list sorted trivially. Repeatedly insert elements one at a time while keeping it sorted. Leads to sorting technique known as Insertion Sort 6 Computer Programming I TA C162 . Insertion sorting Algorithm Steps: Assumptions: arr: Array to be sorted arr_sort: Sorted Array Copy first element of arr to sort_arrr....
View Full Document

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 22

Lec c5 - 1 Computer Programming I TA C162 . Todays Agenda...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online