Reference Http://www.cnblogs.com/zyb428/p/5673738.html#commentformModified some of the code errors.First, direct insertion sortCycle take I=1, to N, then ++i; small loop takes j=i, to 0, then--j; Loop statement: Use temp to compare from small to large.voidInsertsort (intArr[],intN) { for(inti =1; I i) { for(intj = i; J >0; --j) {if(Arr[j] 1]) { inttemp = Arr[j];//swap (
1. Array Basics
1. What is an array:
A collection of data of the same type is a container.
2. Benefits of Arrays:
The zero-based numbering of elements in an array can be automated to facilitate manipulation of the data.
3. Format: (once created, must be clear length)
Format 1:
element type [] Array name = new element type [the number of elements is the length of the array];
Example: int[] array = new INT[5];
Format 2:
element type [] Array name = new element type
1 Select Sort Principle int[] arr = new int[] {2,4,21,44,10}; The first element of the array is compared to the other elements if the value of the element is smaller then the two values are compared so that the maximum value of the array is the maximum value on the 0 index of the array. Now we find out the first and second place how to find it, the reason is very simple, is to think of the remaining elements as a new array, and then repeat the above o
/Verification Code$str = "abcdefghijklmnopqrstuvwxyz0123456789";$a =substr ($str, Rand (0,35), 1);$b =substr ($str, Rand (0,35), 1);$c =substr ($str, Rand (0,35), 1);$d =substr ($str, Rand (0,35), 1);echo $a. $b. $c. $d;The length of the output string$ABC = "Have you eaten?";echo strlen ($ABC);Splitting a string, dividing the array into groups$ABC = "Gently I come, as I quietly walk, waving a wave of sleeves, not take away a cloud";$arr =explode (",",
Array object (Array object) and javascriptarray in JavaScript
1. method for creating an Array object:
---> Var arr = [1, 2, 3]; // simple definition method
Now you can know
Arr [0] = 1; arr [1] = 2; arr [2] = 3; ---> new Array (); var arr = new Array (); // define an array o
...mid] and A[mid+1...high] are merged into an ordered interval A[low...high].
/** Merge Sort implementation process * @param array $arr array of intervals to be sorted * @param int $start The starting position of the first interval array * @param int $mid First interval The end position of the array, the start position of the second interval array * @param Int $end The end position of the second interval array * @return void*/ functionMergeArr
//Bubble SortvoidBubblesort (intArr[],intLen) { //A comparison of two adjacent elements put the big one behind the small put in front of a complete comparison, the maximum value is placed at the end for(intI=1; i//Number of Bubbles//The first time bubble, put the current maximum value to Len-i//bubbling from 0 to Len-i BOOLFlag =false; for(intj=1; j){ if(arr[j]1]){ intTMP =
Common sorting algorithms#include using namespace Std;typedef int ELEMTYPE;/*1. Insert Sort(1) Direct insertion sorting algorithmThe algorithm thought: divides the equal row sequence into the order and the disorderly two parts, then sequentially inserts the unordered part in the already ordered part, finallyYou can form an ordered sequence.The procedure is as follows:1) Find out the insertion position of the element L (i) in the table K;2) The elements before the K element in the table are seque
) Multi-row multi-column use, outer loop control row, Inner loop control column3) Execution Process: Outer loop to walk once, memory cycle go all times4) can use a layer without two layers, can use two layers without three layers, the less layer the betterIf the three-layer loop is exceeded, the design has a problem5) Break can only jump out of a layer of loops3. program = algorithm + data structureAlgorithm: Process/step for problem Solving (order, branch, Loop)Data structure: Save the informat
The array in the PHP4 function manual is complete. I will check the latest manual tomorrow .... Array_values ($ arr) array returns all elements of the array. copy the code -PHP100.com? Php $ arr = array (a, B, c); $ arr = array_flip ($ arr); // reverse the subscript of the array and the current $ arrThe array in the PH
To create an indexed array
$arr =array (' name ' => ' Molaifeng ', ' age ' => ', ' height ' => ' 167 ');
foreach ($arr as $value) {
echo $value. ' ';
}
echo '
when referencing an array cell indexed by a character, the index must be enclosed in single quotes
echo $arr [' name '], '
to determine whether an array is empty
$
Objective:The foreach structure is introduced in PhP4, which is an easy way to iterate through an array. foreach makes it easier to get key-value pairs than a traditional for-loop. Before PhP5, foreach can only be used in arrays, and after php5, it is possible to iterate through the object using foreach (see: Traversing an object). This article only discusses the case of traversing an array.
While foreach is simple, it may cause some unexpected behavior, especially if the code involves referenc
PHP Array function classification, Phparray function
basic functions of array manipulation1, the key name and value of the arrayArray_values ($arr); Get the value of an arrayArray_keys ($arr); Get the key name of the arrayArray_flip ($arr); The values in the array are interchanged with the key names (if there are duplicates, the previous overrides will be follow
We 're not going to tangle with God. Horse is built-in object, God Horse is built-in constructor. By then you will find that they are all objects.Array () is a built-in constructor function that constructs an array:var Newis equivalent to the following:var arr = []; The method of array text table recognitionWhether the array is created in the form of a divine horse, we can add elements to it as usual.Arr[0] = 1; a
C compiler profiling _ 5.2.3 intermediate code generation and optimization _ access array elements and struct members through "offset"
Section 5.2.3 accesses array elements and struct members through "offset"
In the previous section, we introduced the access to "array elements and struct members". We use the "base address + offset" mode to calculate the address of the memory unit. For the array element arr2 [I] [2], the array index value I is a variable, and the corresponding address must be exp
"" "Title: Enter three integers x, y, Z, please put these three numbers from small to large output. "" "Def Inputint (i):" "" Enter and determine whether the input is an integer, not re-enter, is the input integer is returned:p Aram I:: return: "" "while true:a = in Put ("Integer%d:"% i) if A.isdigit (): a = Int (a) break else:print ("Input error, please reenter") return adef Sort1 (arr): "" "Sort output with array:p Aram
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.