# lec32 - Todays Agenda Arraysbasedproblems...

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

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

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

View Full Document
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
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"); }

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

View Full Document
This is the end of the preview. Sign up to access the rest of the 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 / 12

lec32 - Todays Agenda Arraysbasedproblems...

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

View Full Document
Ask a homework question - tutors are online