第三周项目一

来源:互联网 发布:yii框架源码 编辑:程序博客网 时间:2024/06/09 07:37
  1. /* 
  2. 烟台大学计算机学院 
  3.  
  4. 文件名称:shunxubiao.cpp 
  5.  
  6. 作者:刘照京 
  7.  
  8. 完成日期:2017年9月27日 
  9.  
  10. 问题描述:顺序表建立 
  11.  
  12. 输入描述:无 
  13.  
  14. 输出描述:顺序表的值 
  15.  
  16. */  
  17.   
  18.   
  19.   
  20. #include <stdio.h>  
  21. #include <malloc.h>  
  22.   
  23. #define MaxSize 50//存储空间大小宏定义  
  24.   
  25.   
  26. typedef int ElemType;  //定义ElemType为int  
  27. typedef struct  
  28. {  
  29.     ElemType data[MaxSize];  //利用了前面MaxSize和ElemType的定义  
  30.     int length;  
  31. } SqList;  
  32.   
  33. void CreateList(SqList *&L, ElemType a[], int n);//用数组创建线性表  
  34. void DispList(SqList *L);//输出线性表DispList(L)  
  35. bool ListEmpty(SqList *L);//判定是否为空表ListEmpty(L)  
  36.   
  37. int main()//主函数  
  38. {  
  39.     SqList *p;  
  40.   
  41.     ElemType x[6]={1,2,3,4,5,6};  
  42.   
  43.     CreateList(p,x,6);  
  44.   
  45.     DispList(p);  
  46.   
  47.     return 0;  
  48.   
  49. }  
  50.   
  51. void CreateList(SqList *&L, ElemType a[], int n)  
  52. {  
  53.     int i;  
  54.     L=(SqList *)malloc(sizeof(SqList));  
  55.     for (i=0; i<n; i++)  
  56.         L->data[i]=a[i];  
  57.     L->length=n;  
  58. }//创建线性表  
  59.   
  60. void DispList(SqList *L)  
  61. {  
  62.     int i;  
  63.     if (ListEmpty(L))  
  64.         return;  
  65.     for (i=0; i<L->length; i++)  
  66.         printf("%d ",L->data[i]);  
  67.     printf("\n");  
  68. }//输出线性表  
  69.   
  70. bool ListEmpty(SqList *L)  
  71. {  
  72.     return(L->length==0);  
  73. }//空表判断
  74. 运行结果:

  75. 知识点总结:顺序表用数组创建,判断是否为空表。
  76. 学习心得:明白了顺序表的基本算法实现程序







原创粉丝点击