Algorithms that generate non-repeated random numbers can solve problems such as random shuffling and lottery. Some algorithms on the Internet are more conscious and traditional, and simple algorithms are now provided. The following source program contains 36 numbers, which are randomly arranged to generate random numbers that are not repeated.
VaR
AA: array [1 .. 36] of string [2]; // The AA array is an array to be randomly arranged,
{Assign values to the AA array in sequence for 1 .. 36 Fi
swapA-d 45 less than b-d swapA-E ∞ greater than b-e do not swapA-f 3 less than b-f swap
B
A
A
B
A
A
C
D
E
F
4
8
45
20
3
At the point where the weight is the least. F is the new growing point.Similarly, F is compared with the original weight of a (
threshold value, not recursion and use to insert the sort, which can also significantly increase the speedSwap numbers void swap (int *a, int *b) {int tmp;TMP = *a;*a= *b;*B = tmp;}//choose The median of left, center andright int median3 (int *A, int left, int right) {int center = (left+right)/2; if(A[left]>A[Center]) SwapA+left,A+center); if(A[left]>A[Right]) SwapA+left,A+right); if(A[center]>
of val1 ="Endl; cout"addr of Alia ="Endl; return 0;}It seems that the reference is changed by the assignment, in fact the variable represented by the reference is also changed, and the referenced address has not changed, so the reference is not changed (still loyal to the original variable).int 101 ; int *ptr = val; int alia = *ptr; int 202 = val1;After the operation, the Alia reference remains unchanged.Reference type ParametersIn the C language, there is only one way to pass a function argum
) {int i=s,j=2*s; while(jif(Ja[j]>a[j+1]) j=j+1; Small heap get big --and small//if(a[i]a[j]) Break; if(Ja[j]a[j+1]) j=j+1; Big heap Get small --and big if(a[i]>=a[j]) Break; Else{Swap (a[I],a[j]);I=j; J=2*j;}}}void heapsort (inta[],int s,int N) {for (int i=n/2; i>=1;i--) Sift (A,i,n); Build a heap bottom -upShowa, N);for (int i=n; i>1;i--) {Swapa[1],a[i]);Sift (a,1, I-1);}}The time complexity of heap sequencing is O (NLOGN),
, and so on.9.3 Generic definition and its applicationGenerics can be used to define generic methods, generic classes, generic interfaces, and so on. In the definition of these generic structures, a generic type parameter (or placeholder) must be specified, and the type parameter contains a generic type that we define, and we can define multiple generic types at once, such as a generic method swapA generic type name is also written with a certain rule
-deduced to get its template argument double. Therefore, the template function is named swapA function call with a function template named function name, with data arguments dx and dy, deduces the function template arguments, and the process of generating the template definition is called the entity or instantiation of the function template. Similarly, the swapObviously, a function template can generate many different template functions, such as funct
(Ja[j]>a[j+1]) j=j+1; Small heap get big --and small//if(a[i]a[j]) Break; if(Ja[j]a[j+1]) j=j+1; Big heap Get small --and big if(a[i]>=a[j]) Break; Else{Swap (a[I],a[j]);K= (; J=2*j;}}}void heapsort (inta[],int s,int N) {for (int i=n/2; i>=1;i--) Sift (A,i,n); Build a heap bottom -upShowa, N);for (int i=n; i>1;i--) {Swapa[1],a[i]);Sift (a,1. io1);}}The time complexity of heap sequencing is O (NLOGN), which is an unstable sorting
Thinkphp in the volist tag in the control of a certain record of a newline bug
BUGDescription: thinkphp version 2.0 Modproperties are also used to control line breaks for a certain record, such as:volistname="List"ID="VO"MoD="5">{$vo.name}eq name="mod"value="4">
eq>
volist>----The above text is excerpted from the Official Handbook----the actual execution result isfirst row of 4 records (missing one)The second and subsequent lines are 5 records .Change of opinion:ThinkPHP\lib\think\templa
]; a[0] = A[i];//stack top and tail swapA[i]=b; Sift (A,0, I-1);//make r[0...i-1] into a heap } } /*** Build the first heap * *@paramA * is a sorted array *@paramLength * Number of array lengths*/ Private voidCrtheap (intA[],intlength) { intn = length-1; //build the heap and start the heap filtering from the first N/2 record for(inti = N/2; I >= 0; i--) {Sift (A, I, N); } } /** * * @paramR * Array *@paramk
The algorithm teacher gave a hard-pressed proof of the full arrangement. The following is an example:
Analyze the correctness and time efficiency of the following generation algorithm: (for convenience of testing, the source code is appended to the end)
Heappermute(N)
// Generate and arrangeHeapAlgorithm
// Input: a positive integerNAnd a Global ArrayA[1 ..N]
// Output:AFull arrangement of elements in
IfN= 1
WriteA
Else
ForILimit 1To N Do
Heappermute(N-1)
If NIs odd
cache is used.3. Add MySQL configuration Parameters MemlockThis parameter forces the address space of the mysqld process to remain locked in physical memory, which is a very overbearing requirement for the OS. You must start MySQL with the root account to take effect.There is also a more sophisticated way to specify that MySQL uses large page memory (Large page). Large pages of memory on Linux will not be swapped out of physical memory, and Memlock have the same wonderful. The specific configur
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.