第三周 项目一——顺序表的基本运算(1)

问题及代码:
/*     
Copyright (c)2016,烟台大学计算机与控制工程学院     
All rights reserved.     
文件名称:顺序表的基本运算.cpp     
作    者:   周国亮
完成日期:2016年9月17日     
版 本 号:v1.0        
问题描述:测试“建立线性表”的算法CreateList,查看建表结果 
输入描述:无    
程序输出:若干数据。  
*/  
#include<stdio.h>  
#include<malloc.h>  
#define MaxSize 50  
typedef int ElemType;  
typedef struct  
{  
    ElemType data[MaxSize];			//存放顺序表中元素  
    int length;						//存放顺序表的长度  
}List;							    //顺序表的类型定义  
void  CreateList(List *&l, int a[], int n);        //构建函数 
bool  ListEmpty(List *l);						  //判断函数   
void  DispList(List *l);					     //输出函数  
int main()  
{  
    List *sq;  
    ElemType x[6]= {1,2,3,4,5,6};  
    CreateList(sq, x, 6);  
    DispList(sq);  
    return 0;  
}  
void CreateList(List *&l, int a[],int n)  
{  
    int i=0;  
    l=(List *)malloc(sizeof(List));  
    for(i=0; i<n; i++)  
    {  
        l->data[i]=a[i];  
    }  
    l->length=n;  
}  
bool ListEmpty(List *l)  
{  
    if(l->length==0)  
    {  
        return 1;  
    }  
    else return 0;  
}  
void  DispList(List*l)  
{  
    int i=0;  
    if(ListEmpty(l))  
        return;  
    while(i<l->length)  
  
    {  
        printf("%d ",l->data[i]);  
        i++;  
    }  
    printf("\n");  
}  

学习心得:数组形成的顺序表可以自由的增删改查。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值