在vc++上简单搭建环境(包括文件引用)
2024-10-19 06:30:41
1,triplet_head.h 文件
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVER_FLOW -2 typedef int Status;
typedef int ElemType;
typedef ElemType *Triplet; Status init_triplet(Triplet &t, ElemType v1, ElemType v2, ElemType v3);
//构造 Triplet t,并赋予3个元素的值为 v1,v2,v3
Status destroy_triplet(Triplet &t);
//销毁 Triplet t
Status get(Triplet t, int i, ElemType &e);
//用e返回t的第i个元素的值
Status put(Triplet &t, int i, ElemType e); Status isAscending(Triplet t); Status isDescending(Triplet t); Status max(Triplet t, ElemType &e); Status min(Triplet t, ElemType &e);
2,triplet_impl.cpp 文件(首先,需要include "stdafx.h"(stdafx.hinclude了stdio.h);其次,引入stdlib.h和string.h; 再次,引入triplet_head.h)
#include "stdafx.h"
#include "triplet_head.h" #include <stdlib.h>
#include <string.h> Status init_triplet(Triplet &t, ElemType v1, ElemType v2, ElemType v3)
{
t = (ElemType *)malloc(*sizeof(ElemType));
if(!t) return OVER_FLOW;
t[]=v1; t[]=v2; t[]=v3;
return OK;
} Status destroy_triplet(Triplet &t)
{
free(t);
t=NULL;
return OK;
} Status get(Triplet t, int i, ElemType &e)
{
if(i<||i>) return ERROR; e=t[i-];
return OK;
} Status put(Triplet &t, int i, ElemType e)
{
if(i<||i>) return ERROR; t[i-]=e;
return OK;
} Status isAscending(Triplet t)
{
return t[]<=t[] && t[]<=t[];
} Status max(Triplet t, ElemType &e)
{
e= (t[]>=t[])?(t[]>=t[]?t[]:t[]) : (t[]>=t[]?t[]:t[]);
return OK;
}
3,main函数(首先,还是需要include "stdafx.h",其次,引入实现triplet_impl.cpp)
// Triplet.cpp : Defines the entry point for the console application.
// #include "stdafx.h"
#include "triplet_impl.cpp" int main()
{
//初始化
Triplet t;
init_triplet(t, ,,);
//获取第3个元素
ElemType e;
get(t,,e);
printf("e=%d\n",e);
//设置第2个元素
put(t,,);
get(t,,e);
printf("e=%d\n",e);
//判断是否 升序
printf("isAscending=%d\n", isAscending(t));
put(t,,);
printf("isAscending=%d\n", isAscending(t));
//取最大值
max(t,e);
printf("max=%d\n",e);
return ;
}
最新文章
- [LeetCode] Excel Sheet Column Number 求Excel表列序号
- 走进异步编程的世界 - 开始接触 async/await
- C# 中的弱引用 WeakReference
- Imread函数不好使的替用方法
- c#实现每隔规定时间自动执行程序代码
- Linux共享内存(一)
- Java异常处理的误区和经验总结
- GCC 命令行详解 -L 指定库的路径 -l 指定需连接的库名(转载)
- HDU 3634 City Planning (离散化)
- C#调用WebService实例和开发(转)
- LNMP状态管理命令
- SpringBoot+gradle+idea实现热部署和热加载
- [vue]vue基础复习项案例stepbystep
- solr 高亮springdatasolr
- 好玩的Raft动画演示,原理秒懂
- Android学习CursorWrapper与Decorator模式 (转至http://www.cnblogs.com/bastard/archive/2012/05/31/2527944.html)
- Java导包问题
- 常用IDE插件
- Python作业选课系统(第六周)
- 存在单点故障的namenode宕机恢复测试
热门文章
- 20155201 2016-2017-2 《Java程序设计》第一周学习总结
- 20162314 《Program Design &; Data Structures》Learning Summary Of The Eleventh Week
- HeyWeGo第五周项目总结
- luogu P1605 迷宫
- G_M_网络流A_网络吞吐量
- Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)
- hdu 2665 Kth number 主席树
- 读书笔记:提高C++性能的编程技术
- 谈谈刚接触sea.js框架得看法
- org.springframework.transaction 包改成 spring-tx