Data Structure Learning (C ++) - Linear Chain Structure Summary (After the Mark) [1]

zhaozj2021-02-16  58

Seeing this title, some people must make a breath - this kid can be finished, of course, if you have a little sorry, I am a pet. But no matter what you think, write here is just a paragraph, no finished, there is a big part of the back, such as trees, pictures, find, sorting - so many years, or this. It means that I think I feel a summary of the front linear chain structure, and I have a guiding significance for the latter learning: from the previous study, you can learn how to learn the data structure, and how to look at this course correctly - if You can see this value from repeated construction, you can really understand the meaning of this course.

Before starting to summarize, first sort out the previous code, assume that you are using VC6, and you should have these main files in your project: node.h, list.h, stack.h, queue.h, circlist. H, dbllist.h, polynomial.h, expressions.h, matrix.h, a CPP file containing main (). Other test files and applications, such as Simulation.h. If you are not using VC6, how many times you must have a certain back, because a lot of error and Warning. When I was released, I didn't take into account the differences in different compilers. I think as long as the light uses a standard library (just use iostream.h and stdlib.h), do not write weird code, generality should not matter, but This is actually not the case. Therefore, I have to spend some space introduction how to modify the previous code, so this article can only be [1]; however, there is a source code for a timer class behind, even a little compensation.

Differences in compilers of VC6, BCB6, DEV-CPP

These should be the most commonly used IDE environment under Win32, and their compilers are Cl.exe, BCC32.EXE, G . EXE (GNU C ). I didn't have BCB6, so I just took BCC32 instead. The VC6 is more early (98 years), which is not very perfect for C standards, such as the following code:

For (int i = 1; i <10; i ); for (int i = 1; i <10; i );

According to C standards, the scope of I should be in the for loop. However, in VC6, the FOR loop defined in I is still valid, so this code is considered a repetition definition in VC6. I am omitted in the second cycle in parallel in the second cycle. Now, it is very supported in this regard to the C standard in this regard, so, I am not defined by the second i. Let such a code to adapt to the two compilers' solutions, or the second loop variable is changed, or return to C.

INT i; for (i = 1; i <10; i ); for (i = 1; i <10; i );

The = overload in VC6 can not require a function type (default int), and the return value is not required. This is very well understood, = can only be a member function, and the operation object is certain, what is the return value (and Int main () a truth)? But this reasonable practice is to violate the standard (what makes people think of), to BCC32, people don't do it, do not give a return value, you can add Return 0; things, no s s s sin; or define void Operator =, All recognized in the same side. VC7 also requires Operator = must have a return value or a standard power. After fixing the problem as above, BCC32 can be compiled, but it is still a lot of waining, which is caused by the style I wrote. The C standard says that if the function is defined within the class (rather than a declare), that function is automatically inline; that is, the members of my class, the compiler think I want them to become inline functions, but Some functions cannot be inline, so the compiler says "Your requirements are too high, I can't do" - I didn't want you to be tired, self-founded compiler.

After Hu Gong's past BCC32, try to try DEV-CPP, dizzy, hundred Error and Warning. In fact, this is a chain reaction. First, in GNU C , iostream.h is abandoned, it is highly recommended to use iostream (always feel like a great stick), fooled VC6, BCC32 also recognizes this. Changed this, I have a ridiculous WARNING, and the document must have an empty line? ! I used to be compact, there is a space, I have to delete it, I have to listen to you, plus. After these, DEV-CPP passed, without Warning.

After this is modified, those code 3 compilers can be compiled. Look at the compiled EXE file size, the minimum of VC6 (Release version), BCC32 big, DEV-CPP ... big is terrible, I don't know whether it is the parameter problem of the compiler, but GNU C can be used in Win32, it is converted, I don't know if it is this. Suddenly there is an idea, which compiler compiled EXE file run faster?

Which compiler effect is better?

First of all, to write a timer, some people have written the article, I will refer to some people, have made a package, as follows:

#ifndef Timer_H

#define Timer_H

#include

Class Timer

{

PUBLIC:

Timer () {QueryperFormanceFrequency (& FREQUENCY);

Inline void start () {queryperformancecounter (& Timerb);

Inline Double GetTime ()

{

QueryperFormanceCounter (& Timere);

Return (Timere.quadpart - Timerb.quadpart) / (Double) Frequency.quadpart * 1000.0;}

Private:

Large_integer Timerb, Timere, Frequency;

}

#ENDIF

This class is very simple, just like a stopwatch, first () first (), then you can read the lost time with gettime (); then start (), restart the timing. The timing unit is MS.

Now let's test which compiler compiler to run faster. In the back section, people who love time don't want to see, just when I am talking about my dreams.

test program

#include "simulationtest.h"

#include "timer.h"

int main ()

{

Timer a;

Double T = 0;

For (int J = 0; j <10; j )

{

a.Start ();

FOR (int i = 0; i <10; i ) simubanktest ();

T = a.gettime ();

}

Cout << T / 10;

System ("pause");

Return 0;

}

#ifndef simulationtest_h

#define simulationtest_h

#include "simulation.h"

Void Simubanktest ()

{

For (int i = 1; i <11; i )

{

Simulation A (I, 480, 1, 3, 4, 10);

A.Run ();

}

}

#ENDIF

No matter how I write, this test can at least reflect the average performance of the queue in different situations. By the way and the standard library, look at how to write code efficiency. Using STL needs to change the Class Simulation a little code, in fact, this is very simple, the following replacement table:

Queue.h "Queue ISempty () enqueue () Dequeue () Using Namespace Std; Deque Empty () Push_Back () Pop_Front ()

In addition, you have to comment out the results :: run () (PrintResult ();) on my machine (C500, 192RAM, WIN2000SP3, turning off other forescriber procedures):

IDE or compiler BCC32 BCC32-STL VC6 VC6-STL executable file size (Byte) 142, 848 145, 920 61, 440 65, 536 First test results (MS) 32.4848 42.325 35.4724 44.448 Second test results (MS) 32.6191 41.4752 35.662 45.084 Hand three tests Result (MS) 32.8919 41.9856 34.7238 43.9707

The result indicates that the BCC32 compiled is a little bit faster, but the file size is really ... (there is no more DEV-CPP because it is not fair, the generation of more than 400 K, the result of more than 60 MS does not take the result This part is that the reason is that my code is caused, such as running a simple mathematical operation test.

#include

#include "timer.h" int main ()

{

Timer a;

a.Start ();

Double S = 0, T;

For (INT i = 1; i <= 10; i )

{

T = 1;

For (int J = 1; j <= i; j ) t * = j;

S = T;

}

Cout << a.getime ();

Return 0;

}

BCC32 is still nearly 140K, 0.00530794ms; VC6 is less than 60K, 0.00335238ms; VC6 leads BCC32 in size and speed.

The results also show that we write the queue, performance is better than the BCC32 and VC6 STL, which is a bit unfair to VC6. Many people know that VC6's Deque performance is not good, how to be shorter than people. Seeing this result, I can't help but, after all, the personal bruises drums, the performance is better than the STL of the manufacturer. In fact, this is only a lot of investment in STL, I took the SGI-STL (VC6 compilation) test, the size of 70K was compiled, the result is roughly 15ms, more than my code efficiency is double, sweat ...

Note: How to use SGI-STL in VC6

First, download a SGI download a STL, 216K ZIP package, really a great masterpiece ... Online is a full word. Different STL.zip to a directory, such as C: / Sgistl, then in the VC6 IDE environment, Tools-> Options-> Directories-> include Files, add C: / SGISTL (you decompressed directory) to go in, then , Move this path to the top, it is OK. Also note that using VC6 uses SGI-STL, you cannot contain , instead of (the dead standard). If you want to use VC6 STL, you only need to move C: / SGISTL to the bottom side, it is too simple (this is the benefit of IDE). BCC32 is not so easy, BCB6 I didn't try it, so I don't know if it's a solution.

In summary, if you start learning C on Win32, VC6 is the best choice, powerful function, a simple interface, high performance (better using SGI-STL). As for the future, you use VC or BCB, that is, look at your application direction and personal preference. - Oh, another garbage article came out. In addition, STL is all source code format, which high person studied why SGI-STL is very good? Tell me, the source code can make people dizziness.

转载请注明原文地址:https://www.9cbs.com/read-22988.html

New Post(0)