/* Set the keyword in the order table is incremented and orderly, the Sentinel is set at the edge of the index, the design algorithm to achieve a simple sequential lookup */
#include "stdio.h"
#include "malloc.h"
#define LIST_SIZE 20
typedef struct{
Charr[list_size];
Intlength; Length is the number of elements in the table
}recordlist;
Recordlist *sqlset () {//Build Order table
Recordlist*l;
Inti=0;char C;
L= (recordlist*) malloc (sizeof (recordlist));
scanf ("%c", &c);//Enter a character
L->length= 0;
while (c!= ' # ') {
l->r[i]=c;
l->length++;
i++;
if (l->length== list_size-1) break;
scanf ("%c", &c);
}
return (L);
}
int Sequensearch (recordlist *l,char k,intn) {//implementation at the end of the index, simple order lookup element
Inti=0,position=-1;//position the location to find
l->r[n]=k;//the last unit as a lookout.
while (n!=i) {
if (l->r[i]== k) {
Position= i+1;
Break
}
i++;
}
Returnposition;
}
int main () {
Recordlist*a;
Intm;
Charc;
printf ("Please enter data (character type)");
A= Sqlset ();
printf ("Please enter the element to find");
C=getchar ();//Eat a return character.
scanf ("%c", &c);
m= Sequensearch (a,c,a->length);
if (m==-1)
printf ("The lookup is unsuccessful. ");
Else
printf ("m=%d, find success. ", m);
Return0;
}
To run a screenshot: