主题:个人写的顺序表的基本题
#include<stdio.h>
#define MAX 100
typedef int KeyType;
typedef char InfoType[10];
typedef struct {
KeyType key;
InfoType info;
}NodeType;
typedef NodeType SeqList[MAX];
int SeqSearch(SeqList R,int n,KeyType k){
int i=0;
for(i=0;i<n;i++){
if(R[i].key==k) break;
printf("%d ",R[i].key);
}
if(i==n) return -1;
else {
printf("%d",R[i].key);
return i;
}
}
int main(){
int i,k,pos, n=10,a[10];
SeqList R;
for(i=0;i<n;i++){
a[i]=i;
R[i].key=i;
}
k=3;
if((pos=SeqSearch(R,n,k))==-1)
printf("\n%d Not Find\n",k);
else printf("\n%d is find at pos %d\n",k,pos+1);
}
#define MAX 100
typedef int KeyType;
typedef char InfoType[10];
typedef struct {
KeyType key;
InfoType info;
}NodeType;
typedef NodeType SeqList[MAX];
int SeqSearch(SeqList R,int n,KeyType k){
int i=0;
for(i=0;i<n;i++){
if(R[i].key==k) break;
printf("%d ",R[i].key);
}
if(i==n) return -1;
else {
printf("%d",R[i].key);
return i;
}
}
int main(){
int i,k,pos, n=10,a[10];
SeqList R;
for(i=0;i<n;i++){
a[i]=i;
R[i].key=i;
}
k=3;
if((pos=SeqSearch(R,n,k))==-1)
printf("\n%d Not Find\n",k);
else printf("\n%d is find at pos %d\n",k,pos+1);
}