Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab021
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab021
提交
62d270c6
提交
62d270c6
5月 20, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
f3f1d752
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
24 行删除
+24
-24
main.c
main.c
+24
-24
没有找到文件。
main.c
浏览文件 @
62d270c6
...
@@ -3,24 +3,24 @@
...
@@ -3,24 +3,24 @@
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
SeqTable
ST
;
//
线性表
SeqTable
ST
;
//
Linear table
int
i
,
pos1
,
pos2
;
int
i
,
pos1
,
pos2
;
//
//
//
初始化线性表
//
Initialize the linear table
//
//
InitSeqTable
(
&
ST
);
InitSeqTable
(
&
ST
);
//
//
//
折半查找
//
Binary search
//
//
pos1
=
BinarySearch
(
&
ST
,
60
);
pos1
=
BinarySearch
(
&
ST
,
60
);
pos2
=
BinarySearch
(
&
ST
,
30
);
//
查找失败
pos2
=
BinarySearch
(
&
ST
,
30
);
//
To find the failure
printf
(
"%d %d
\n
"
,
pos1
,
pos2
);
printf
(
"%d %d
\n
"
,
pos1
,
pos2
);
//
//
//
销毁线性表
//
Destroy linear table
//
//
DeleteSeqTable
(
&
ST
);
DeleteSeqTable
(
&
ST
);
...
@@ -28,16 +28,16 @@ int main(int argc, char* argv[])
...
@@ -28,16 +28,16 @@ int main(int argc, char* argv[])
}
}
/*
/*
功能:
function:
折半查找。
Binary search.
参数:
parameter:
pST --
线性表指针
pST --
Linear table pointer
key --
查找关键字
key --
search key
返回值:
returned value:
如果查找成功返回关键字在表中的位置
Returns the position of the keyword in the table if the lookup is successful
如果查找失败返回 0
Returns 0 if the lookup fails
*/
*/
int
BinarySearch
(
SeqTable
*
pST
,
KeyType
key
)
int
BinarySearch
(
SeqTable
*
pST
,
KeyType
key
)
{
{
...
@@ -46,38 +46,38 @@ int BinarySearch(SeqTable* pST, KeyType key)
...
@@ -46,38 +46,38 @@ int BinarySearch(SeqTable* pST, KeyType key)
int
mid
;
int
mid
;
//
//
// TODO:
在此添加代码
// TODO:
Add the code here
//
//
return
0
;
return
0
;
}
}
/*
/*
功能:
function:
初始化线性表。
Initialize the linear table.
参数:
parameter:
pST --
线性表指针
pST --
Linear table pointer
*/
*/
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
// 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
};
//
顺序必须为从小到大
int
InitArray
[]
=
{
2
,
4
,
11
,
18
,
25
,
32
,
39
,
46
,
53
,
60
,
67
,
74
};
//
The order must be from smallest to largest
void
InitSeqTable
(
SeqTable
*
pST
)
void
InitSeqTable
(
SeqTable
*
pST
)
{
{
int
i
;
int
i
;
pST
->
length
=
sizeof
(
InitArray
)
/
sizeof
(
InitArray
[
0
]);
pST
->
length
=
sizeof
(
InitArray
)
/
sizeof
(
InitArray
[
0
]);
pST
->
elem
=
(
ElemType
*
)
malloc
((
pST
->
length
+
1
)
*
sizeof
(
ElemType
));
//
因为单元 0 留空,所以长度必须加
1
pST
->
elem
=
(
ElemType
*
)
malloc
((
pST
->
length
+
1
)
*
sizeof
(
ElemType
));
//
Because the 0 is left blank, the length must be increased by
1
for
(
i
=
1
;
i
<=
pST
->
length
;
i
++
)
for
(
i
=
1
;
i
<=
pST
->
length
;
i
++
)
pST
->
elem
[
i
].
key
=
InitArray
[
i
-
1
];
pST
->
elem
[
i
].
key
=
InitArray
[
i
-
1
];
}
}
/*
/*
功能:
function:
销毁线性表。
Destroy linear table.
参数:
parameter:
pST --
线性表指针
pST --
Linear table pointer
*/
*/
void
DeleteSeqTable
(
SeqTable
*
pST
)
void
DeleteSeqTable
(
SeqTable
*
pST
)
{
{
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论