Lec32 - Computer Programming I TA C162 Today's Agenda...

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

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 7 Apr 2007 Today’s Agenda Arrays  based problems 1. Searching-> Linear Search, Binary Search 2. Sorting -> Bubble Sort (Done), Insertion Sort (Done)      Merge Sort 3. Strings-> Word reversing
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 7 Apr 2007 Linear search Each item in the list is examined in the order in which it occurs in the list until the desired item is found or the end of the list  is reached Algorithm   // precondition : N>=1 1. Read a array of N elements named List[0…N-1] and search  element key 2. Repeat for i=0 to i=N-1  1. If key equals to List[i]  1. Display element found and stop 3. Display element not found 4. Stop Post condition : If i<N element found otherwise element not           found
Background image of page 2
3 Computer Programming I TA C162 . 7 Apr 2007 main() // Linear search implementation { int List[10],index,key; printf("Enter Array elements:"); for(index = 0; index<10; index++) scanf("%d",&List[index]); printf("Enter search element"); scanf("%d", &key); for(index=0;index<10; index++) if(key==List[index]) { printf("Element found at %d location",index); return; } printf("Element not found"); }
Background image of page 3

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

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

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 12

Lec32 - Computer Programming I TA C162 Today's Agenda...

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

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