9.25.c

来自「数据结构习题及答案」· C语言 代码 · 共 29 行

C
29
字号
实现下列函数:
int Search(SSTable s, KeyType k);
/* Index the element which key is k */
/* in StaticSearchTable s.          */
/* Return 0 if x is not found.      */

静态查找表的类型SSTable定义如下:
typedef struct { 
    KeyType key;  
    ... ...    // 其他数据域
} ElemType;

typedef struct {
    ElemType *elem;
    int       length;
} SSTable;
int Search(SSTable a, KeyType k)
/* Index the element which key is k  */
/* in StaticSearchTable s.           */
/* Return 0 if x is not found.       */
{
  int i;
  a.elem[a.length+1].key=k;
  for(i=1;a.elem[i].key!=k;i++);
  if(i>a.length) return ERROR;
  return i;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?