- #1
Sumaya
- 29
- 0
Homework Statement
A company has a number of employees whose records, for simplicity, contain:
Employee number Employee name
Write separate programs, each of which searches for a key whose value is to be input, using the sequential search variations given below. Let each program initialize the data to the sample given.
a) a straight sequential search algorithm.
b) a sentinel search algorithm.
c) a probability search algorithm.
i didn't know what the underline means ?
is it required to use the hash function or my solution for part a is right ?
Homework Equations
emp # emp name
121267 Ali Mohammed
045128 Samir Hasan
379452 Majid Sabri
160252 Tawfiq Faris
378845 Basil Ali
070918 Saddiq mahmod
166702 Husain Khalid
572556 Jamil Yasir
167010 Zaid Amr
The Attempt at a Solution
Code:
#include<iostream>
using namespace std;
const int arraySize = 1000;
struct employee
{
char name[arraySize];
int number;
};
int main()
{
employee arr[9]={"Ali Mohammed",121267,"Samir Hasan",45128,"Majid Sabri",379452,"Tawfiq Faris",160252,"Basil Ali",378845,"Saddiq mahmod",70918,"Husain Khalid",166702,"Jamil Yasir",572556,"Zaid Amr",167010};
int size=17;
int target,flag,n=9,i;
cin>>target;
i=0;
while(i<n)
{
if(target==arr[i].number)
{
flag=1;
break;
}
i++;
}
if(flag)
cout<<"found"<<" "<<arr[i].name<<endl;
else
cout<<"not found "<<i<<endl;
return 0;
}
thanx alot