Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to define the use of C language strings and arrays

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the C language string and array how to define the use of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you will get something after reading this C language string and array definition and use article, let's take a look.

Strings and arrays

String abbreviation string is a special linear table, whose particularity is that the data element is only composed of one character. As a basic data type, characters are of great significance in computer information processing, and the object of computer non-numerical processing is often string data. In addition, string has its own characteristics, and a string is often treated as a whole. Therefore, it is very necessary to study the concept of string as an independent structure. This chapter briefly introduces the storage structure and basic operation of the string.

Array can be regarded as a generalization of linear table, which is characterized by that the data element in the table is still a table. In essence, the data elements in the array with dimension greater than 1 are no longer a simple one-to-one relationship, so strictly speaking, the multi-dimensional array is nonlinear. However, because of the consistency of the types of data elements in the array and the identity of its internal structure, the array and its operations can be realized with the help of linear table when dealing with the array. This chapter will introduce the logical structure and storage structure of the array, sparse matrix and its compressed storage and so on.

Section 1: string

1.1 the basic concept of string

A String is a sequence of characters consisting of zero or more arbitrary strings. Remember: s = "a1a2 an", where s is the string name. A1 (1data [p] .j; B-> data [Q] .j = A-> data [p] .I; B-> data [Q] .v = A-> data [p] .v; qdata;}} if (B-> tu > 0) {return B;}}

According to the analysis of the algorithm, its time is mainly spent on the double cycle of col and p, so the time complexity is O (n × t) (let m and n be the number of rows and columns of the original matrix, and it is the number of non-zero elements of the sparse matrix). Obviously, when the number of non-zero elements t and m × n are of the same order of magnitude, the time complexity of the algorithm is O (m × n ²), which may save a certain amount of storage space compared with the matrix transpose algorithm under the usual storage mode. But the time complexity of the algorithm is even worse.

Algorithm improvement: the reason for the inefficiency of the above algorithm is that the algorithm needs to find the first column, the second column and the repeated search of A from the triple table of A. if you can directly determine the position of each triple in An in B, you can scan the triple table of A. This can be done, because the first non-zero element of the first column in A must be stored in B.data [1]. If you also know the number of non-zero elements in the first column, then the position of the first non-zero element in the second column in B.data is equal to the position of the first non-zero element in the first column plus the number of non-zero elements in the first column. And so on, because the triples in An are stored first and then columns, for the same row, you must encounter elements with small column numbers first, so you only need to scan the A.data once.

According to the above idea, two vectors need to be introduced: Num [n + 1] and col [n + 1], num [col] represents the number of non-zero elements of the col column in matrix A (to facilitate the use of both from unit 1), and the initial value of cpot [col] represents the position of the first non-zero element of the col column in matrix An in the matrix. So the initial value of cpot is: cpot [1] = 1 Cpot [col] = cpot [col-1] + num [col-1]; 2nub; B-> nu = A-> mu; B-> tu = A-> tu; if (B-> to > 0) {for (num [I] = 0) {num [I] = 0;} for (iTun1; itu; iBun +) {jungA-> data [I] .j; numn [j] + } cpot [1] = 1; / find the position of the first non-zero element of each column in B.data in matrix A for (I = 2; inu;i++) {cpot [I] = CPO [I-1] + Num [I-1];} for (I = 1; itu); iScan +) {/ / scan triple table j = A-> data [I] .j K = cpotj; B-> data [k] .I = A-> data [k] .j; B-> data [k] .j = A-> data [I] .I; B-> data [k] .v = A-> data [I] .v;} return B;}

Analyze the time complexity of this algorithm: there are four loops in this algorithm, which execute n, t, nmur1, t times respectively. In each cycle, the actual value of each iteration is a constant, so the total time complexity is O (nperft). Of course, it requires two more vectors than the previous algorithm.

This is the end of the article on "how to define the use of strings and arrays in C language". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to define the use of strings and arrays in C language". If you want to learn more, you are welcome to follow the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report