您的位置:首页 > 其它

第三周 项目一 顺序表的基本运算

2017-12-26 20:10 260 查看
#include <iostream>   
#include <malloc.h>  
using namespace std;  
typedef int kong;  
typedef struct  
{  
     int data[50];  
     int length;  
}sqlist;  
void Createlist(sqlist*&L,kong a[],int n);//建立一个空的线性表  
void DispList(sqlist *L);//顺序输出线性表的内容。  
int ListEmpty(sqlist *L);//判断线性表是否为空;  
int main()  
{  
     sqlist *sq;  
     kong b[5]={1,2,3,4,5};  
     Createlist(sq,b,5);  
     DispList(sq);  
     return 0;  
}  
void Createlist(sqlist*&L,kong a[],int n)  
{  
     int x;  
     L=(sqlist *)malloc(sizeof(sqlist));  
     for(x=0;x<n;x++)  
          L->data[x]=a[x];  
          L->length=n;  
}  
void DispList(sqlist *L)  
{  
     int x;  
     if(ListEmpty(L)==1)  
          return;  
     for(x=0;x<L->length;x++)  
          cout<<L->data[x];  
     cout<<endl;  
}  
int ListEmpty(sqlist *L)  
{  
     return (L->length==0);  
}  
运行结果:

知识点总结:
实现顺序表基本运算,运用了viod和int函数,又用指针和链表。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: