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

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

2.int InitList_Sq (SqList*   L)

  int InitList_Sq (SqList   *L)

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

Sqlist.h

#include 
#include 
#include 
#define OK 1
#define ERROR 0
#define OVERFLOW 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef 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



你可能感兴趣的:(C语言,数据结构)