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 ;
}

最新文章

  1. [LeetCode] Excel Sheet Column Number 求Excel表列序号
  2. 走进异步编程的世界 - 开始接触 async/await
  3. C# 中的弱引用 WeakReference
  4. Imread函数不好使的替用方法
  5. c#实现每隔规定时间自动执行程序代码
  6. Linux共享内存(一)
  7. Java异常处理的误区和经验总结
  8. GCC 命令行详解 -L 指定库的路径 -l 指定需连接的库名(转载)
  9. HDU 3634 City Planning (离散化)
  10. C#调用WebService实例和开发(转)
  11. LNMP状态管理命令
  12. SpringBoot+gradle+idea实现热部署和热加载
  13. [vue]vue基础复习项案例stepbystep
  14. solr 高亮springdatasolr
  15. 好玩的Raft动画演示,原理秒懂
  16. Android学习CursorWrapper与Decorator模式 (转至http://www.cnblogs.com/bastard/archive/2012/05/31/2527944.html)
  17. Java导包问题
  18. 常用IDE插件
  19. Python作业选课系统(第六周)
  20. 存在单点故障的namenode宕机恢复测试

热门文章

  1. 20155201 2016-2017-2 《Java程序设计》第一周学习总结
  2. 20162314 《Program Design &amp; Data Structures》Learning Summary Of The Eleventh Week
  3. HeyWeGo第五周项目总结
  4. luogu P1605 迷宫
  5. G_M_网络流A_网络吞吐量
  6. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)
  7. hdu 2665 Kth number 主席树
  8. 读书笔记:提高C++性能的编程技术
  9. 谈谈刚接触sea.js框架得看法
  10. org.springframework.transaction 包改成 spring-tx