In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
I would like to share with you what the three storage structures in computer programming are. I believe most people don't know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. let's learn about it!
Yes, a string is a linear table structure with special data objects and operations. The string mentioned in the data structure, that is, the string; the characters in the string have a "one-to-one" logical relationship, so strictly speaking, the string storage structure is a linear storage structure.
The operating environment of this tutorial: windows7 system, Dell G3 computer.
The string mentioned in the data structure, that is, the string, is a whole of n characters (n > = 0). These n characters can be composed of letters, numbers, or other characters.
In the data structure, strings are stored in a separate storage structure, which is called string storage structure.
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 learned before, the string structure is only used to store data of character types.
Special string
Empty string: a string containing zero characters. For example: s = "" (there is nothing in double quotation marks), which is usually expressed directly as @.
Space string: a string that contains only spaces. Note that the space string is distinguished from the empty string, there is content in the space string, but it contains spaces, and the space string can contain multiple spaces. For example, a = "" (containing 3 spaces).
Substring and main string: a string consisting of any consecutive characters in a string is called a substring of the string, and the string containing the substring is called the primary string.
For example: a = "BEI", b = "BEIJING", c = "BJINGEI". For strings an and b, because b contains consecutive strings a
So a can be called a substring of b, and b is the main string of a; for c and a, although c also contains all the characters of a, it is not a continuous "BEI", so the string c has no relationship with a.
The position of the substring in the main string: for the string a = "BEI", the position of the first character'B' in string b is 1, so the position of substring an in the main string b = "BEIJING" is 1.
The position of the substring in the main string is different from the position of the characters in the array, and the position of the substring in the main string starts at 1.
The criterion that two strings are equal: if the string values of two strings are exactly the same, then the two strings are equal.
Three kinds of storage structure of string
There are three kinds of structure of storage string:
1 fixed length sequential storage
2 heap allocated storage
3-block chain storage.
Fixed-length sequential storage
Uses a fixed-length array (that is, a static array) storage string.
For example: char a [7] = "abcdfg"
When storing a string in this way, you need to estimate the length of the string and apply for sufficient storage space in advance. If the target string exceeds the length of the array application, the excess is automatically discarded (called "truncation").
For example: char a [3] = "abcdfg"; / / actually only "abc" is stored in the array, and the latter is truncated. Heap allocated storage
Using dynamic array storage string
In C language, there is a free storage area called "heap", which is managed by malloc function and free function, malloc function is responsible for applying for space, and free function is responsible for releasing space.
For example:
Char* a = (char*) malloc (5*sizeof (char)); / / create an array of an and dynamically apply for storage space for 5 char type data
The advantage of using the heap to allocate storage is that when you find that the requested space is insufficient, you can reapply for more storage space through the realloc () function.
For example: a = (char*) realloc (a, 10*sizeof (char)); / / the previous parameter refers to the object applying for space; the second parameter refers to the size of the reapplied space.
The storage space requested by using the malloc function is not automatically released, but needs to be manually released by the programmer by calling the free () function. If it is not released manually, it will be reclaimed by the operating system when the execution of the program is completely completed.
For example: free (a); / / release the space requested by the dynamic array a
To take a complete example, the connection strings "abc" and "defg" become "abcdefg"
# include # include # include int main () {char* A1 null; char* a2 null; A1 = (char*) malloc (3*sizeof (char)); strcpy (A1, "abc"); / / copy the string "abc" to A1 a2 = (char*) malloc (3*sizeof (char)); strcpy (a2, "defg"); int lengthA1=strlen (A1); int lengthA2=strlen (a2); if (lengthA1)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.