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:

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

  • 相关阅读:
    delphi shr和shl的作用
    delphi socket 编程 使用多线程
    mysql 移除服务,并在cmd下切换目录
    delphi 结构体和TList的用法
    delphi 使用工控机控件 iThreadTimes 出现问题, 导致主程序创建页面的时候, 阻塞消息, 不能正常执行。
    Unicode 和 UTF-8 的区别
    Python 模块 re (Regular Expression)
    Python的函数式编程
    反向解析与PTR(Pointer Record)
    simhash算法
  • 原文地址:https://www.cnblogs.com/q1204675546/p/9891181.html
Copyright © 2011-2022 走看看