C語言之建立線性表


#include<stdio.h>
#include<stdlib.h>
#define MaxSize 60
#define ElemType int

typedef struct {
    ElemType data[MaxSize];
    int length;
}SqList;

void CreateList_Sq(SqList *&L,ElemType a[],int n){//建立線性表 
    int i;
    L = (SqList *)malloc(sizeof(SqList));    /*分配存放線性空間*/
    for(i = 0;i < n;i++){
        L -> data[i] = a[i];
    }
    L -> length = n;    /*令線性表L的長度為n*/
}

int main(){
    SqList * L;
    int i;
    ElemType a[] = {1,2,3,4,5};
    CreateList_Sq(L,a,sizeof(a)/sizeof(int));
    for(i = 0;i < 5;i++){
        printf("%d\n",L->data[i]);
    }
    return 0;
} 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM