Home > Back-end >  Data structure guo-hua geng for unit 8
Data structure guo-hua geng for unit 8

Time:12-01

#include
# define list_size 20
Typedef int keytype;
Typedef int othertype;
Typedef struct
{
Othertype key;
Keytype other_data;
} recordtype;
Typedef struct
{
[list_size recordtype r + 1];
Int length;
} recordlist;
//sequential search, a lookout
Int seqsearch (recordlist l, keytype k)
{
int i;
Their lives [0]. Key=k;
I=l.l ength;
While (their lives [I]. The key!=k)
i--;
return i;
}
//sequential search, not a lookout
Int SeqSearch (recordlist l, keytype k)
{
int i;
I=l.l ength;
While (i>=1 & amp; & Their lives [I]. The key!=k)
i--;
If (i>
=1)return i;
The else
return -1;
}
//binary search
Int rinsrch (recordlist l, keytype k)
{
Int mid;
Int low=0;
Int high=l.l ength;
While (low<=high)
{
Mid=+ high (low)/2;
If (k==their lives [mid] key)
Return mid;
Else if (kHigh=mid - 1;
The else
Low=mid + 1;
}
}
Void main ()
{

}
The main function how to write ah
  • Related