zoukankan      html  css  js  c++  java
  • 头文件的编写和引用

          我用的是 Dev-c++  编写头文件

    首先写头文件里面的函数,

    然后保存,记得后缀写  .h   就行

    例:(顺序表的头文件)

    #define MAXSize 50
    #define OVERFLOW -2
    #define ElemType int
    using namespace std;
    typedef struct List{
    ElemType *elem;
    int length;
    }SqList;
    void InitList(SqList &L)
    { //构造一个空的顺序表
    L.elem=new ElemType[MAXSize];
    if (!L.elem)
    exit(OVERFLOW);
    L.length=0;
    }
    void ClearList(SqList &L)
    { //清空线性表,不销毁
    L.length=0;
    }
    int ListLength (SqList L)
    { //求线性表长度
    return (L.length);
    }
    bool ListInsert (SqList &L, int i , ElemType e)
    { //在线性表L中第i个数据元素之前插入新数据元素e
    int j;
    if (i<1||i>L.length+1)
    return false;
    if (L.length>=MAXSize)
    return false;
    for (j=L.length;j>=i;--j)
    L.elem[j]=L.elem[j-1];
    L.elem[i-1]=e;
    ++L.length;
    return true;
    }
    ElemType GetElem(SqList L, int i)
    { //在线性表L中求序号为i的元素,该元素作为函数返回值
    if (i<1||i>L.length){
    printf("i不在[1..n]范围内");
    exit(OVERFLOW);
    }
    return (L.elem[i-1]);
    }
    #define MAXSize 50
    #define OVERFLOW -2
    #define ElemType int
    using namespace std;
    typedef struct List{
    ElemType *elem;
    int length;
    }SqList;
    void InitList(SqList &L)
    { //构造一个空的顺序表
    L.elem=new ElemType[MAXSize];
    if (!L.elem)
    exit(OVERFLOW);
    L.length=0;
    }
    void ClearList(SqList &L)
    { //清空线性表,不销毁
    L.length=0;
    }
    int ListLength (SqList L)
    { //求线性表长度
    return (L.length);
    }
    bool ListInsert (SqList &L, int i , ElemType e)
    { //在线性表L中第i个数据元素之前插入新数据元素e
    int j;
    if (i<1||i>L.length+1)
    return false;
    if (L.length>=MAXSize)
    return false;
    for (j=L.length;j>=i;--j)
    L.elem[j]=L.elem[j-1];
    L.elem[i-1]=e;
    ++L.length;
    return true;
    }
    ElemType GetElem(SqList L, int i)
    { //在线性表L中求序号为i的元素,该元素作为函数返回值
    if (i<1||i>L.length){
    printf("i不在[1..n]范围内");
    exit(OVERFLOW);
    }
    return (L.elem[i-1]);
    }

    然后保存

    头文件就写好了,然后引用 

    方法1:

      #include"E:List.h"             //   #include"  头文件存放路径+头文件名"

    方法2:

      将编写的头文件 和  正准备调用          该头文件      的项目文件放在同一个文件夹里面

  • 相关阅读:
    POJ-1004-Finanical Management
    POJ-1003-hangover
    第一次写博客,想了很久要给自己留一个什么样的开始
    从exchange2010上面删除特定主题或特定时间的邮件
    STM32 一个定时器产生4路 独立调频率,占中比可调,脉冲个数可以统计。
    光电耦合
    STM32 定时器级联
    Eclipse 创建新的workspace
    一次提交,多文件上传
    Grid标签计算结果集中的合计行
  • 原文地址:https://www.cnblogs.com/q1204675546/p/9891181.html
Copyright © 2011-2022 走看看