【数据结构】线性表之顺序表的创建

来源:互联网 发布:防辐射眼镜 知乎 编辑:程序博客网 时间:2024/06/08 15:54

1.C语言中是没有引用的

2.int InitList_Sq (SqList*   L)

  int InitList_Sq (SqList   *L)

  无论如何写都是一样的,该函数的参数是L 也就是指向SqList顺序表的指针  而不是*L

Sqlist.h

#include <stdio.h>#include <conio.h>#include <stdlib.h>#define OK 1#define ERROR 0#define OVERFLOW 0#define LIST_INIT_SIZE 100#define LISTINCREMENT 10typedef struct{ int *elem; int length; int listsize;} SqList;int InitList_Sq (SqList*   L){ (*L).elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!(*L).elem)  exit(OVERFLOW); (*L).length=0; (*L).listsize=LIST_INIT_SIZE; return OK;}

Sqlist.cpp

// Sqlist.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "Sqlist.h"int CreateList_Sq ( SqList *L ){ int i; printf("Input the datas:"); for(i=0;i<(*L).length;i++)  scanf("%d",&((*L).elem[i])); return OK;}int  main(){ int i,n; SqList L; InitList_Sq(&L); printf("Input the length of the list L:"); scanf("%d",&n); L.length=n; CreateList_Sq(&L); printf("Output the datas:"); for(i=0;i<L.length;i++)  printf("%d ",L.elem[i]); printf("\n"); return 0;}



0 0
原创粉丝点击