The Sqlist for Linear table | Data

简介: The Code in Data book (5th Edition) from the 35 page to 37 page

The Code in Data book (5th Edition) from the 35 page to 37 page

#define MaxSize 50
typedef int ElemType;

//Sqlist structure
typedef struct{
    ElemType data[MaxSize]; //save Sqlist elements
    int length; //save Sqlist length
} SqList;

//Create Sqlist
void CreateList(SqList *&L, ElemType a[], int n) {
    L = (SqList *) malloc(sizeof(SqList));
    for ( int i = 0; i < n; i++ )
        L->data[i] = a[i];
    L->length = n;
}

//Initialization Sqlist
void InitList(SqList * &L){
    L = (SqList *)malloc(sizeof(SqList));//Allocate space for Sqlist
    L->length = 0;//Make empty linear table length 0
}

//Destroyed Sqlist
void  DestroyList(SqList *&L) {
    free(L);
}

//Determine if a Sqlist is empty
bool ListEmpty(SqList *L) {
    return (L -> length == 0);
}

//Find the length of Sqlist
int ListLength(SqList *L) {
    return(L->length);
}

//Output Sqlist
void DispList(SqList *L) {
    for (int i = 0; i < L->length; i++)//Scan Sqlist outputs values for each element
        printf("%d ", L->data[i]);
    printf("\n");
}

//Find the value of a data element in the Sqlist
bool GetElem(SqList *L, int i, ElemType &e) {
    if ( i < 1 || i > L->length )
        return false;      //When parameters i error return false
    e = L->data[i - 1];    //Get elements value
    return true;           //When find elements success return true
}

//When position elements e success on Sqlist, find in order of elements values
int LocateElem(SqList *L, ElemType e) {
    int i = 0;
    while (i < L-> length && L->data[i] != e)
        i++;            //Find elements e
    if (i >= L->length) //Return 0 when not found
        return 0;
    else
        return i + 1;    //return logical sequence number when found
}

//Insert data elements
bool ListInsert(SqList *&L, int i, ElemType e) {
    int j;
    if (i<1 || i > L->length + 1)
        return false;//Return false when wrong parameters i
    i--;//Corvert Sqlist logical serical numbers to physical serial numbers
    for (j = L->length; j > i; j--) //Move the data[i] and rear all elements back one position
        L->data[j] = L->data[j - 1];
    L->data[i] = e;//Insert elements e
    L->length++;//Sqlist length add 1
    return true;
}

//Delete data elements
bool ListDelete(SqList *&L, int i, ElemType &e) {
    int j;
    if (i<1 || i > L->length)
        return false;//return false when wrong paraments
    i--;             //Convert sequential table logical serial numbers to physical serial numbers
    e = L->data[i];
    for (j = i; j < L->length - 1; j++)  //Move the data[i] and rear all elements forward one position
        L->data[j] = L->data[j + 1];
    L->length--;//Sqlist length minus 1
    return true;//return true success;
}
By Homework 1

如有侵权,请联系作者删除

目录
相关文章
|
6月前
【echarts报错】line series not exists,should be same with series name or data name
【echarts报错】line series not exists,should be same with series name or data name
237 0
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
516 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
The Linknode for Linear table | Data
The Code in Data book (5th Edition) from the 49 page to 52 page
81 0
The Double Linknode for Linear table | Data
The some code in Data book (5th Edition) from the 54 page to 55 page
95 0
|
数据挖掘 开发者
Data-Measuring Data Similarity and Dissimilarity| 学习笔记
快速学习 Data-Measuring Data Similarity and Dissimilarity。
Data-Measuring Data Similarity and Dissimilarity| 学习笔记
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
|
数据库
Data truncation: Out of range value for column ‘estimate_score‘
Data truncation: Out of range value for column ‘estimate_score‘
成功解决linear_model\stochastic_gradient.py:128: FutureWarning: max_iter and tol parameters have been ad
成功解决linear_model\stochastic_gradient.py:128: FutureWarning: max_iter and tol parameters have been ad
|
Web App开发 Java 关系型数据库
Data truncation: Data too long for column &#39;xxx&#39; at row 1
Data truncation: Data too long for column 'xxx' at row 1 完整的错误内容可能是下面这样的: p.p1 {margin: 0.0px 0.0px 0.
2243 0