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

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

目录
相关文章
|
存储 SQL 关系型数据库
【MySQL异常】Row size too large (> 1982). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNA
【MySQL异常】Row size too large (> 1982). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNA
157 0
|
8月前
【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
307 0
|
关系型数据库 MySQL 数据库
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
1722 0
|
4月前
|
SQL 关系型数据库 MySQL
MySQL 8.0报错--1118-Row size too large. The maximum row size for the used table type, not counting BLOBs,is 8126,
MySQL 8.0报错--1118-Row size too large. The maximum row size for the used table type, not counting BLOBs,is 8126,
MySQL 8.0报错--1118-Row size too large. The maximum row size for the used table type, not counting BLOBs,is 8126,
|
8月前
|
索引 Python
row[i] = col[j] = TrueIndexError: list assignment index out of range
row[i] = col[j] = TrueIndexError: list assignment index out of range
|
8月前
|
关系型数据库 MySQL
MySQL【问题 02】报错 1709 - Index column size too large. The maximum column size is 767 bytes. 可能是最简单的方法
MySQL【问题 02】报错 1709 - Index column size too large. The maximum column size is 767 bytes. 可能是最简单的方法
241 0
|
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
545 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
92 0
The Double Linknode for Linear table | Data
The some code in Data book (5th Edition) from the 54 page to 55 page
100 0
|
Python
You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.conca
You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.conca
803 0

热门文章

最新文章