提交 7e57b542 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 bc6a75fa
#ifndef SEQTABLE_H_
#define SEQTABLE_H_
//
// Include the C standard library header file here
//
#include <stdio.h>
//
// Other header files are included here
//
//
// Define the data structure here
//
// Elements in a linear table
typedef int KeyType;
typedef struct ElemType {
typedef struct ElemType
{
KeyType key; // Primary key
// Omit other data and no longer define
}ElemType;
// The sequential storage structure of a linear table
typedef struct SeqTable {
ElemType* elem; // Data element storage space base address, allocated according to the actual length when the table is built,
typedef struct SeqTable
{
ElemType* elem; // Data element storage space base address,
// allocated according to the actual length when the table is built,
// Unit 0 is left blank and is used from unit 1.
int length; // The length of the table
}SeqTable;
......@@ -43,12 +41,8 @@ int BinarySearch(SeqTable* pST, KeyType key);
void InitSeqTable(SeqTable* pST);
void DeleteSeqTable(SeqTable* pST);
//
// Declare global variables here
//
#endif /* SEQTABLE_H_ */
#include "SeqTable.h"
int main(int argc, char* argv[])
{
SeqTable ST; // Linear table
......@@ -59,17 +58,22 @@ function:
parameter:
pST -- Linear table pointer
*/
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
int InitArray[] = { 2, 4, 11, 18, 25, 32, 39, 46, 53, 60, 67, 74 }; // The order must be from smallest to largest
// The order must be from smallest to largest
int InitArray[] = { 2, 4, 11, 18, 25, 32, 39, 46, 53, 60, 67, 74 };
void InitSeqTable(SeqTable* pST)
{
int i;
pST->length = sizeof(InitArray) / sizeof(InitArray[0]);
pST->elem = (ElemType*)malloc((pST->length + 1) * sizeof(ElemType)); // Because the 0 is left blank, the length must be increased by 1
// Because the 0 is left blank, the length must be increased by 1
pST->elem = (ElemType*)malloc((pST->length + 1) * sizeof(ElemType));
for(i=1; i<=pST->length; i++)
for (i=1; i<=pST->length; i++)
{
pST->elem[i].key = InitArray[i-1];
}
}
/*
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论