3 Sequential Search 8 Sequential search int seqsearchint
- Slides: 36
3
������ Sequential Search 8
Sequential search int seqsearch(int data[], int n, int key) { int pos; if(key<=data[n-1]) for(pos = 0; pos<n; pos++) if(data[pos] == key) return pos; return -1; /* no data found */ } 9
#include <stdio. h< #define N 10 int table[N] = {1, 2, 3, 5, 6, 7, 10, 22, 23, 31; { int seqsearch(int data[], int n, int key; ( void printlist(int data[], int n; ( Ex 3 void main(void( } int search, result; printlist(table, N( printf("Please enter a data to search ; (“ : scanf("%d", &search; ( result = seqsearch(table, N, search; ( if(result >= 0( printf("Data found at location %dn", result; ( else printf("No such data in the tablen; (" { 10
int seqsearch)int data[], int n, int key( } int pos; if(key<=data[n-1]) for)pos=0; pos<n; pos(++ if(data[pos] == key ( return pos; return -1; /* no data found/* { void printlist(int data[], int n( } int pos; for(pos=0; pos<n; pos(++ printf("%2 d ", data[pos; ([ printf("n; (" { 11
Ex 4 จงเขยนโปรแกรมเพอกรอกขอมลอายของนกศก ษา 10 คน (แบบเรยงลำดบ )แลวทำการคนหาวาอายทต องการอยในลำดบทเทาไรโดยใช Sequential Search Input Output Age 1: 14 Age 2: 15 Age 3: 16 Age 4: 18 Age 5: 19 Age 6: 21 Age 7: 22 Age 8: 23 Age 9: 24 Age 10: 26 Enter Search Age : 18 Result = 4 Enter Search Age : 24 Result = 9 Enter Search Age : 20 Result = Not Found 12
#include <stdio. h> int input)int data([] } Solution Ex 4 int seqsearch(int data[], int n, int key( } 13
void main() { 14
15
Ex 6 กำหนดใหคา search = 7 [0] [1] [2] [3] [4] [5] [6] X 1 6 9 10 12 17 23 24 Last First รอบท [7] 1 21
Ex 6 search = 7 (ตอ ( 22
Ex 6 search = 7 (ตอ ( 23
int binarysearch(int data[], int n, int key) { int first, last, mid; first=0; last=n-1; while(first<=last) { mid =(last+first)/2; /*find the center */ if(key < data[mid]) /*move the range down */ last = mid-1; else if(key > data[mid]) /*move range up*/ first = mid+1; else return mid; } return -1; /* no data found */ } 25
#include<stdio. h< #define N 10 Ex 7 int table[N]={1, 2, 3, 5, 6, 7, 10, 22, 23, 31; { int binarysearch(int data[], int n, int key; ( void printlist(int data[], int n; ( void main(void( } int search, result; printf(“Data in TABLEn; (": printlist(table, N; ( printf")Please enter a data to search; (" : scanf("%d", &search; ( result = binarysearch(table, N, search; ( if(result>=0( printf("Data found at position %dn", result; ( else printf("No such data in the tablen; (" { 26
int binarysearch(int data[], int n, int key) { int first, last, mid; first=0; last=n-1; while(first<=last) { mid =(last+first)/2; /*find the center */ if(key < data[mid]) /*move the range down */ last = mid-1; else if(key > data[mid]) /*move range up*/ first = mid+1; else return mid; } return -1; /* no data found */ } 27
void printlist)int data[], int n( } int pos; for(pos=0; pos<n; pos(++ printf("%2 d ", data[pos; ([ printf("n; (" { 28
Ex 8 จงเขยนโปรแกรมเพอรบจำนวนนกศกษา และกรอกคะแนนของนกศกษาตามจำนวนทร บ (แบบเรยงลำดบ ) แลวทำการคนหาวาคะแนนทตองการอย ในลำดบทเทาไหรโดยใช Output Binary Search Input Enter num of student : 6 Student 1: 15. 6 Student 2: 16 Student 3: 18. 75 Student 4: 19. 32 Student 5: 21. 56 Student 6: 28 Enter Search Score : 21. 56 Student No. = 5 Enter Search Score : 15. 6 Student No. = 1 Enter Search Score : 17. 75 Student No. = Not Found 29
#include <stdio. h> int input)float data([] Solution Ex 8 30
int binarysearch(float data[], int n, float key) { 31
void output)int r( } 32
void main() } 33
Question? 34
Input Weight 1: 35. 5 Weight 2: 46 Weight 3: 58. 75 Weight 4: 49. 32 Weight 5: 61. 56 Weight 6: 40. 2 Weight 7: 48. 75 Weight 8: 59. 35 Weight 9: 57. 56 Weight 10: 48 Output Before Sorting : 35. 5 46 58. 75 49. 32 61. 56 40. 2 48. 75 59. 35 57. 56 48 After Sorting : 35. 5 40. 2 46 48 48. 75 49. 32 57. 56 58. 75 59. 35 61. 56 Enter Key Weight : 59. 35 Position : 9 ************ Bye ************* 36
- Int sum(int a int n) int sum=0 i
- Interface calculator public int add(int a int b)
- Public void drawsquare(int x, int y, int len)
- Divideint
- Int max(int x int y)
- List the advantages and disadvantages of binary search?
- Void swap(int a int b)
- 7팩토리얼
- Int f (int n)
- Interface myinterface int foo(int x)
- Arduino const int
- Mainint
- Max int
- Int main int argc char argv
- Int main int num 4
- What is sequential search
- Sequential search flowchart
- Sequential search
- Logical organization
- Kekurangan sequential search
- Sequential search java
- Sequential search java
- Http://tw
- Federated search vs discovery
- Https://images.search.yahoo.com/search/images
- Video.search.yahoo.com search video
- Semantic search vs cognitive search
- èinterest
- Best first search
- Videos yahoo search
- Which search strategy is called as blind search
- Federated search vs distributed search
- Search by image
- Uninformed search methods
- 1http
- Informed search and uninformed search in ai