/*
*Copyright (c) 2015,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:王敏
*完成日期:2015年09月14日
*版本号:v1.0
*
*问题描述:测试“建立线性表”的算法ListLength、GetElem、LocateElem函数
*输入描述:
程序输出:
*/
#include <stdio.h>
#include <malloc.h>
#define MaxSize 50 //Maxsize将用于后面定义存储空间的大小
typedef int ElemType; //ElemType在不同场合可以根据问题的需要确定,在此取简单的int
typedef struct
{
ElemType data[MaxSize]; //利用了前面MaxSize和ElemType的定义
int length;
} SqList;
//自定义函数声明部分
void CreateList(SqList *&L, ElemType a[], int n);//用数组创建线性表
void DispList(SqList *L);//输出线性表DispList(L)
bool ListEmpty(SqList *L);//判定是否为空表ListEmpty(L)
int ListLength(SqList *L); //求线性表的长度ListLength(L)
bool GetElem(SqList *L,int i,ElemType &e); //求某个数据元素值GetElem(L,i,e)
int LocateElem(SqList *L, ElemType e); //按元素值查找LocateElem(L,e)
//实现测试函数
int main()
{
SqList *sq;
ElemType x[6]= {5,8,7,2,4,9};
第三周项目1-(2)ListLength、GetElem、LocateElem函数
最新推荐文章于 2024-11-21 04:00:00 发布