• 周二. 9 月 10th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Postgraduate entrance examination data structure (c + + language) — sequential query

King Wang

1 月 15, 2022
Ordinary sequential query

#include<iostream>
using namespace std;
int easy_sort(int arr[],int n,int key);
int main(){
int arr[8] = {1,2,3,4,5,6,7,8};
int index=easy_sort(arr,8,4);
cout<<" Index found :" <<index;
}
int easy_sort(int arr[],int n,int key){
for(int i=0;i<n;i++){
if(key==arr[i]) return i;
}
return -1;
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

With sentries The order of the query

#include<iostream>
using namespace std;
int seq_search(int arr[],int n,int key);
int main(){
int arr[8] = {1,2,3,4,5,6,7,8};
int index=seq_search(arr,8,4);
cout<<" Index found :" <<index;
}
int seq_search(int arr[],int n,int key){
int i=n;
while(arr[i]!=key) i--;
return i;
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

发表回复