Data structure (3)-string, array and generalized table
Partly reproduced by LUOFANG SHIJIE
string
Strings, like linear tables, have sequential storage structures and chained storage structures, but in consideration of efficiency issues, sequential storage structures are often used
Sequential storage structure
#define Maxsize 255
typedef struct
{
char ch[Maxsize +1]; //存储串的一维数组
int length; //串的当前长度
}SString;
For the convenience of explanation, generally the strings stored sequentially start with a subscript of 1, and the component with a subscript of 0 is left untouched.
typedef struct
{
char *ch;
int length;
}HString;
The sequential storage of arrays
1. The storage method based on column order
2. Row order as the main order storage method
Generalized table
Extension of linear tables
Three characteristics of generalized tables:
- The elements of the generalized table can be sub-tables, and the elements of the sub-tables can also be sub-tables
- Generalized tables can be shared by other tables
- The generalized table can be a recursive table, that is, the generalized table itself can also be a sub-table of itself
Two important operations in generalized tables
- Header taken: The header taken out is the first element of a non-empty generalized table. It can be a single atom or a sublist.
- Take the end of the table: The taken end of the table is a table composed of the rest of the elements except the head, and the tail must be a generalized table.
Generalized table storage structure
Generalized tables often use a chain storage structure (the storage structure of the head and tail linked lists and the storage structure of the extensible linked list)