第三周项目一(1)

/*
烟台大学计算机与控制工程学院

文件名称:main.cpp,1.cpp,list.h

作者:王硕

完成日期:2017年9月15日

问题描述:顺序表的基本运算(1)

*/
#include <iostream>
#include "list.h"

using namespace std;

int main()
{
    SqList *sq;
    ElemType x[6]= {5,8,7,2,4,9};
    CreateList(sq, x, 6);
    if(ListEmpty(sq))
          cout<<"此线性表为空!";
    else
          DispList(sq);

    return 0;

}
//1.cpp

#include <stdio.h>
#include <malloc.h>
#include "list.h"

//用数组创建线性表
void CreateList(SqList *&L, ElemType a[], int n)
{
    int i;
    L=(SqList *)malloc(sizeof(SqList));
    for (i=0; i<n; i++)
        L->data[i]=a[i];
    L->length=n;
}


//输出线性表DispList(L)
void DispList(SqList *L)
{
    int i;
    if (ListEmpty(L)) return;
    for (i=0; i<L->length; i++)
        printf("%d ",L->data[i]);
    printf("\n");
}


//判定是否为空表ListEmpty(L)
int ListEmpty(SqList *L)
{
    if(L->length==0)
        return 1;
    else
        return 0;
}
//list.h

#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED

#define MaxSize 50
typedef int ElemType;
typedef struct
{
    ElemType data[MaxSize];
    int length;
} SqList;
void CreateList(SqList *&L, ElemType a[], int n);//用数组创建线性表
int ListEmpty(SqList *L);//判定是否为空表ListEmpty(L)
void DispList(SqList *L);//输出线性表DispList(L)
#endif // LIST_H_INCLUDED



运行结果:


学习心得:这次让我感受到了用顺序表的基本算法实现程序

总结感受:先编写完成基本算法,再调用搭配,很有乐趣。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值