the problem is:the sequential search alogirthm will always find the first occurrence of an item in a data set creat a new sequential search method that takes a second integer argument indicating whichoccurrence of an item you want to search for
the problem is in the forloop
and i want to know is this code is right?
Code:#include<iostream> using namespace std; int i; int myarr[10]; int t=myarr[i]; int key; int index; int seqsearch(int myarr()) for(i=0;i<10;i++) { for(int j=i-1;j>=0 && t<myarr[j];j--) { myarr[i]=rand()%100; cout<<myarr[i]<<endl; } } void main() { int myarr[10]; int t=myarr[i]; int key; int index; cout<<"plz enter the key"<<endl; cin>>key; bool found=false; for(int i=0;i<10;i++) { for(int j=i-1;j>=0 && t<myarr[j];j--) { myarr[i]=rand()%100; cout<<myarr[i]<<endl; if(myarr[i]==key) found=true; index=i; } } if(found==false) else cout<<"invalid key"<<endl ; }