提交 9f3f8698 创建 作者: 宋海霞's avatar 宋海霞

template

上级
流水线 #468 已失败 于阶段
/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/Lab003.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
#ifndef _LINEARLIST_H_
#define _LINEARLIST_H_
//
// 在此处包含 C 标准库头文件
//
#include <stdio.h>
//
// 在此处包含其他头文件
//
//
// 在此处定义数据结构
//
#define MAX_LENGTH 20 // 线性表的最大长度
typedef int ElemType; // 线性表中元素的类型
typedef struct {
ElemType Elements[MAX_LENGTH]; // 使用数组存储线性表中的元素,线性表的最大长度即为数组长度。
int nLength; // 线性表的实际长度,即线性表中元素的个数。
}SqList;
//
// 在此处声明函数
//
int Delete(SqList* pList, int i, ElemType* pElem);
#endif /* _LINEARLIST_H_ */
<?xml version="1.0" encoding="gb2312"?>
<OSLProject Version="1.00" Name="LinearList_Delete" SubjectID="cf4dda31-1275-49ef-9b0f-36a6eff372e4" ProjectTemplateID="ec0accdf-2e9f-4253-9d63-b5df538c60d3">
<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\LinearList_Delete_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
<VisualContext>
<WatchPoints>
<WatchPoint FunctionName="Delete" ObserverID="4A545808-487C-4680-B248-8541CD235EC7">
</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=".\LinearList.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>
#include "LinearList.h"
int main(int argc, char* argv[])
{
SqList List;
int i;
ElemType Elem;
//
// 初始化线性表
//
List.nLength = 8;
for(i=0; i<List.nLength; i++)
List.Elements[i] = i;
//
// 删除第 i 个元素
//
Delete(&List, 6, &Elem);
Delete(&List, 15, &Elem); // 删除位置非法。删除失败。
for(i=0; i<List.nLength; i++)
{
printf("%d ",List.Elements[i]);
}
printf("\n");
return 0;
}
/*
功能:
删除第 i 个元素。
参数:
pList -- 线性表
i -- 删除元素的位置。从 1 开始计数。
pElem -- 返回被删除元素的值。
返回值:
如果删除成功返回 1
如果删除失败返回 0
*/
int Delete(SqList* pList, int i, ElemType* pElem)
{
int nIndex; // 用于移动元素的游标
//
// TODO: 在此添加代码
//
return 0;
}
app:main.o
gcc -o app main.o
main.o:main.c LinearList.h
gcc -c -w -O3 -std=c99 -fsigned-char main.c -o main.o
0 1 2 3 4 6 7
# 阅读实验源代码
**main.c文件**
在main函数中实现了线性表的初始化,然后调用了两次线性表的删除函数Delete,第一次调用删除成功,第二次调用删除失败。
在main函数的后面,定义了线性表的删除函数Delete,此函数的函数体还不完整,留给读者完成。
**LinearList.h文件**
定义了与线性表相关的数据结构并声明了相关的操作函数。
# 在演示模式下调试项目
**按照下面的步骤调试项目:**
1. 按F7生成项目。
2. 在演示模式下,按F5启动调试项目。程序会在观察点函数的开始位置中断。
3. 重复按F5,直到调试过程结束。
在调试的过程中,每执行“演示流程”窗口中的一行后,仔细观察“可视化数据”窗口所发生的变化,例如线性表元素的复制,游标的移动等,理解在线性表中删除元素的执行过程。
# 编写源代码并通过验证
**按照下面的步骤继续实验:**
1. 为Delete函数编写源代码。注意,尽量使用已定义的局部变量。
2. 按F7生成项目。如果生成失败,根据“输出”窗口中的提示信息修改源代码中的语法错误。
3. 按Alt+F5启动验证。如果验证失败,可以使用“输出”窗口中的“比较”功能,或者在“非演示模式”下按F5启动调试后重复按F10单步调试读者编写的源代码,从而定位错误的位置,然后回到步骤1。
# 教师参考答案
访问教师参考答案[domain relative url](engintime/ds-lab/teachers-packet/Lab003.git)
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论