Home  >  Article  >  What is the structure of a string?

What is the structure of a string?

青灯夜游
青灯夜游Original
2020-07-18 12:08:0524491browse

String is a linear storage structure, because the characters in the string also have a "one-to-one" logical relationship. However, unlike the linear storage structure we learned before, the string structure is only used to store character type data.

What is the structure of a string?

#In the data structure, strings are stored in a separate storage structure, which is called a string storage structure. The string here refers to the string.

Strictly speaking, the string storage structure is also a linear storage structure, because the characters in the string also have a "one-to-one" logical relationship. However, unlike the linear storage structure we learned before, the string structure is only used to store character type data.

No matter which programming language you learn, strings are always the most manipulated. In the data structure, some special strings are named according to the number and characteristics of the characters stored in the string, for example:

  • Empty string: stores a string of 0 characters, such as S = "" (double quotes next to each other);

  • Space string: a string containing only space characters, such as S = " " (double quotes contain 5 spaces);

  • Substring and main string: Suppose there are two strings a and b. If a string consisting of several consecutive characters can be found in a that is exactly the same as b, then a is said to be the main string of b. b is a substring of a. For example, if a = "shujujiegou", b = "shuju", since a also contains "shuju", string a and string b are the relationship between the main string and the substring;

It should be noted that the space string is different from the empty string. The space string contains characters, but they are all spaces. In addition, only if string b appears entirely in string a, can it be said that b is a substring of a. For example, "shujiejugou" and "shuju" are not related to the main string and substring.

In addition, for two strings with a relationship between a main string and a substring, you are usually asked to use an algorithm to find the position of the substring in the main string. The position of the substring in the main string refers to the position of the first character of the substring in the main string.

For example, string a = "shujujiegou", string b = "jiegou", through observation, you can judge that a and b are the relationship between the main string and the substring, and at the same time, the substring b is located at the 6th position in the main string a. position, because in string a, the position of the first character 'j' of string b is 6.

Specific implementation of string storage structure

To store a string, the data structure contains the following three specific storage structures:

  • Fixed-length sequential storage: In fact, it is stored in an ordinary array (also known as a static array). For example, the code for using ordinary data to store strings in C language is char a[20] = "data.biancheng.net";

  • Heap allocated storage: use dynamic arrays to store strings;

  • Block chain storage: use linked list to store strings;

For more related knowledge, please visit:PHP Chinese website !

The above is the detailed content of What is the structure of a string?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn