提交 0b5f8237 创建 作者: 宋海霞's avatar 宋海霞

template

上级
流水线 #487 已失败 于阶段
/Debug
/Release
*.bak
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_cpp:latest"
stages:
- make
- case1
- teacher-check
variables:
TEMPLATE_REPO: "engintime/ds-lab/Project-Template/Lab023.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
make:
stage: make
<<: *codecode-runner
script:
- make
- execscore.sh 40
only:
- master
case1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app > user_output.txt
- diff output.txt user_output.txt -b -B -y -i --suppress-common-lines
- execscore.sh 100
only:
- master
teacher-check:
stage: teacher-check
<<: *codecode-runner
script:
- make
- ./app
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEMPLATE_REPO} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/output.txt output.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
only:
- master
when: manual
allow_failure: false
<?xml version="1.0" encoding="gb2312"?>
<OSLProject Version="1.00" Name="SearchHash" SubjectID="cf4dda31-1275-49ef-9b0f-36a6eff372e4" ProjectTemplateID="c53a69e6-b8e0-41c4-945f-edfc9c003dea">
<Configurations>
<Configuration Name="Debug">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" AdditionalDependencies="&quot;$(DSLInstallDir)Dump\lib\SearchHash_Linearity_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
<VisualContext>
<WatchPoints>
<WatchPoint FunctionName="Hash" ObserverID="6F639898-6359-4d74-BD46-99B48710D030">
</WatchPoint>
</WatchPoints>
</VisualContext>
</Configuration>
<Configuration Name="Release">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="ͷļ" Filter="h;hpp;hxx">
<File RelativePath=".\SearchHash.h">
</File>
</Filter>
<Filter Name="Դļ" Filter="cpp;c;cc;cxx">
<File RelativePath=".\main.c">
</File>
</Filter>
<File RelativePath=".\makefile">
</File>
<File RelativePath=".\output.txt">
</File>
<File RelativePath=".\readme.md">
</File>
</Files>
</OSLProject>
#ifndef _SEARCHHASH_H_
#define _SEARCHHASH_H_
//
// 在此处包含 C 标准库头文件
//
#include <stdio.h>
//
// 在此处包含其他头文件
//
//
// 在此处定义数据结构
//
#define HASH_LEN 20 // 哈希表的长度
// 哈希表
typedef struct hterm{
int key; // 关键字
int si; // 再散列次数
}HASH;
//
// 在此声明函数
//
void Hash(int* KeyArray, int length); // 哈希函数
//
// 在此处声明全局变量
//
extern HASH HashList[HASH_LEN];
#endif /* _SEARCHHASH_H_ */
添加文件
#include "SearchHash.h"
HASH HashList[HASH_LEN];
int main(int argc, char* argv[])
{
int i;
//
// 初始化关键字数组
//
int KeyArray[] = {19, 14, 35, 54, 68, 75, 94, 27, 55, 11, 15, 79};
int length = sizeof(KeyArray)/sizeof(KeyArray[0]);
//
// 构造哈希表
//
Hash(KeyArray, length);
printf("\nSubscript\tRehashesCount\tKeyword\t\n");
for(i = 0; i<HASH_LEN; i++)
{
printf("%d", i);
printf("\t\t\t%d", HashList[i].si);
printf("\t\t\t\t%d", HashList[i].key);
printf("\n");
}
return 0;
}
/*
功能:
用给定的一组关键字数组构造哈希表。
参数:
KeyArray -- 关键字数组指针
length -- 数组的长度
*/
void Hash(int* KeyArray, int length)
{
int i; // 游标
int j; // 增量
int address; // 哈希地址
int count; // 再散列次数
int newaddress; // 新哈希地址
//
// TODO: 在此添加代码
//
}
app:main.o
gcc -o app main.o
main.o:main.c SearchHash.h
gcc -c -w -O3 -std=c99 -fsigned-char main.c -o main.o
Subscript RehashesCount Keyword
0 5 55
1 6 15
2 3 79
3 0 0
4 0 0
5 0 0
6 0 0
7 0 27
8 0 68
9 0 0
10 0 0
11 0 11
12 0 0
13 0 0
14 0 14
15 0 35
16 2 54
17 2 75
18 4 94
19 0 19
# 阅读实验源代码
**main.c文件**
在main.c文件中,首先在main函数前定义了一个全局的哈希表结构体数组,然后在main函数中初始化了一个关键字数组并调用哈希表创建函数Hash用给定的关键字数组创建哈希表,最后在Windows控制台中打印输出哈希表。
在main函数的后面,定义了哈希表创建函数Hash,此函数的函数体还不完整,留给读者完成。
**SearchHash.h文件**
定义了与哈希表相关的数据结构并声明了相关的操作函数。
# 在演示模式下调试项目
**按照下面的步骤调试项目:**
1. 按F7生成项目。
2. 在演示模式下,按F5启动调试项目。程序会在观察点函数的开始位置中断。
3. 重复按F5,直到调试过程结束。
在调试的过程中,每执行“演示流程”窗口中的一行后,仔细观察“可视化数据”窗口内容所发生的变化,理解哈希表创建的执行过程。“可视化数据”窗口显示的数据信息(如下图所示),包括:
- 用于构造哈希表的关键字数组和游标。
- 哈希表。对应的当前值与上一次值不相同,用红色的字体显示;已加入哈希表的关键字所在行的填充色为灰色。
![创建哈希表(线性探测再散列)](./img/23.png)
# 编写源代码并通过验证
**按照下面的步骤继续实验:**
1. 为Hash函数编写源代码。注意,尽量使用已定义的局部变量。
2. 按F7生成项目。如果生成失败,根据“输出”窗口中的提示信息修改源代码中的语法错误。
3. 按Alt+F5启动验证。如果验证失败,可以使用“输出”窗口中的“比较”功能,或者在“非演示模式”下按F5启动调试后重复按F10单步调试读者编写的源代码,从而定位错误的位置,然后回到步骤1。
# 教师参考答案
访问教师参考答案[domain relative url](engintime/ds-lab/teachers-packet/Lab023.git)
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论