Operation:

1
InitList(L):初始化操作,

任务:

1
2
3
4
/*
1.定义线性表类型的对象L。
2.初始化线性表L,并输出其长度。
*/

代码实现:

  • C

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include<stdio.h>
    #define OK 1
    #define ERROR 0
    #define TRUE 1
    #define FALSE 0

    #define MAXSIZE 20

    typedef int ElemType;//抽象数据类型,是线性表中数据元素的数据类型。
    typedef int Status;//抽象数据类型,是函数返回值的类型

    typedef struct
    {
    ElemType data[MAXSIZE];
    int length;
    }SqList;

    Status InitList(SqList L)
    {
    L.length = 0;
    return OK;
    }
    int main()
    {
    SqList L;//定义一个顺序结构的线性表。
    Status i;

    i = InitList(L);//初始化线性表L。

    printf("L.length = %d\n",L.length);//输出线性表的长度。
    }
  • C++

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    #include<iostream>
    using namespace std;
    #define OK 1
    #define ERROR 0
    #define TRUE 1
    #define FALSE 0

    #define MAXSIZE 20

    typedef int ElemType;//抽象数据类型,是线性表中数据元素的数据类型。
    typedef int Status;//抽象数据类型,是函数返回值的类型

    typedef struct
    {
    ElemType data[MAXSIZE];
    int length;
    }SqList;

    Status InitList(SqList L)
    {
    L.length = 0;
    return OK;
    }
    int main()
    {
    SqList L;//定义一个顺序结构的线性表。
    Status i;

    i = InitList(L);//初始化线性表L。

    cout<<"L.length = "<<L.length<<endl;//输出线性表的长度。
    }
  • java

    1