Study notes C # arrays

the System the using; 
the using the System.Collections.Generic; 
the using the System.Linq; 
the using the System.Text; 
the using System.Threading.Tasks; 

namespace Project4 
{ 
    class Program 
    { 
        static void the Main (String [] args) 
        { 
            // main inlet 
            // the method defined space array 
            // int [] = ARR new new int [10] {. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9, 10}; 
            int [] = {ARR 10, 32, 42 is , 55, 77, 3, 89, 13, 11, 100}; 
            // array flip 
            // the reversed (ARR);        
            // the specified position to the specified value      
            // INSERT (ARR, 0, 1111); 
            // delete the specified array specified value 
            // deleteValue (arr, 115);
            deleteValue2 (ARR, 77); 
            // delete the specified target element 
            // deletespecificSUB (ARR, 0); 
                                    // Add an array 
                                    // int [] = {11,11,11,99} BRR; 
                                    // insertArrdataTo (ARR , 2, BRR); 
            // specified value replacement 
            // replace (ARR, 77, 44 is); 
            //Console.WriteLine(indexof(arr,11)); 
            // Console.WriteLine (lastIndexOf (ARR, 400)); 
                                     ascending order // 
                                     // fromMintoMax (ARR); 
                                     // delete the specified position to a specified position value 
                                       // deletekinddata (arr, 0,2);
                                       // deletekinddata2 (arr, 0, 2 ); // call  
            // delete the specified position specified length of element
            // deletecountdata (ARR, 0,2); 
            arrshow (ARR); // After the above change, the array vary 
            Console.ReadKey (); // Console.ReadLine (); 

        } 
        /// <Summary> 
        /// array reversal 
        /// </ Summary> 
        /// <param name = "ARR"> array passed from the outside </ param> 
        static void the reversed (int [] ARR) 
        { 
            // int I = (int) (arr.length / 2); 
            number of times // computes the array, required operations: half of the total length 
            for (int a = 0; a <arr.Length / 2; A ++) 
            { 
                // reference to bubble and selection. Namely: use an intermediate variable, as a temporary space. 
                int t;
                // will be an array in the penultimate (second to last ......) assigned to t. 
                t = arr [arr.Length - 1 - a];
                ARR [arr.length -. 1 - A] = ARR [A]; 
                // In this case, the memory address is the name of t corresponding to the part of the value assignment 
                ARR [A] = t; 
            }            
        } 
        /// <Summary> 
        / // the value is inserted at a specified position of the specified array 
        /// </ summary> can not be changed since the length of the array, so that when the value is inserted as the value after overwriting a 
        /// <param name = "arr" > incoming array </ param> 
        /// <param name = "index"> insert position </ param> 
        /// <param name = "value"> added value </ param> 
        static void iNSERT (int [] ARR, int index, int value) 
          // static void INSERT (int [] ARR, index,
              for (int I =-arr.length. 1; I> index; i--) 
            { 
                // the number used directly in front of the rear coverage value) 
                // find the specified value in the array 
                ARR [I] = ARR [I -. 1 ];
            }     
              // Assignment, will give a value to index position        
            ARR [index] = value;             
        } 
        /// <Summary> 
        value /// Remove the specified array variable custom         
        /// </ summary> can not be changed since the length of the array , after a register value addition 
        /// to move forward so the value of the back, the last value to 0 
        /// <param name = "ARR"> </ param> 
        /// <param name = "value"> < / param> 
        static void deleteValue (int [] ARR, int value) 
        { 
            // loop through the array 
            for (int I = 0; I <=. 1-arr.length; I ++) 
            {
                IF (ARR [I] == value) 
                { 
                    // starting from the current location, a value of a front cover after use 
                    for (int I = J; J <arr.length -. 1; J ++) 
        } 
        // you can call: 
        static void deleteValue2 (int [] arr, int value)
                    { 
                        ARR [J] = ARR [J +. 1]; 
                    } 
                } 
                // another method, using indexof. 
                the else 
                { 
                    //Console.WriteLine ( "delete fails, not found!"); 
                    return; 
                } 


            } 
            // end of the array 0 is assigned 
            ARR [arr.length -. 1] = 0; 
        { 
            // definition of a variable, perhaps in memory standard 
            int index = indexOf (ARR, value);             
            // change to delete the target value. Why is the index, rather than index ++: because, after deleting an index value behind, to forward a grid 
            deletespecificSUB (arr, index); 
        } 

        /// <the Summary>
        /// Remove the specified array subscripts value, the variable custom 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "index"> </ param > 
        static void deletespecificSUB (int [] ARR, int index) 
        { 
            // searching out array 
            for (int I = 0; I <= arr.length -. 1; I ++) 
            { 
                // index is determined 
                if (i == index) 
                    searching out therefrom // array          
                    for (int I = J; J <arr.length -. 1; J ++) 
                    { 
                        a value // value with a front cover 
                        arr [j] = arr [j + 1];
                    }
                }
            }
            // last assigned 0 
            ARR [arr.length -. 1] = 0; 
        } 
        /// <Summary> 
        /// array at a specified position, the array into another value 
        /// </ summary> array is inserted , the length of the array must be less than the length of arr 
        /// <param name = "arr"> </ param> 
        /// <param name = "index"> as the insertion starts subscript </ param> 
        static void insertArrdataTo (int [] ARR, int index, int [] BRR) 
        { 
            // add restrictions if, coverage problems. Create a new array 
            // array of two arrays and a total length less than a length of the array 
            after the first move operation // 
            
            for (int I = index; I <index + brr.Length; I ++) 
            { 
                
                // when to insert and the original length of the array elements and the number of array elements is greater than the head of the original 
                
                    // original array element moves rearwardly
                    ARR [I + brr.Length] = ARR [I]; Wu //   
                    // ARR [I] = ARR [I - brr.Length]; 
                    // data populated   
                      
                
            } 
            // Wang: value into the cycle. Also consider the number of insertion 
            for (int J = 0; J <brr.Length && index <arr.length; J ++, index ++) 
            { 
                ARR [index] = BRR [J]; 
            } 
               
        } 
        /// <Summary> 
        /// and the values specified in the array, replace the value specified 
        /// </ Summary> 
        /// <param name = "newValue"> Numerical administered </ param> 
        static void Replace (int [] ARR, int oldValue, 
        /// <param name = "ARR"> array </ param>
        /// number </ param> <param name = "oldValue"> to be replaced
            for (int i = 0; i < arr.Length; i++)
           for (int I = 0; I <arr.length; I ++) 
            { 
                // find 
                IF (ARR [I] == oldValue) 
                { 
                    // do replace where 
                    ARR [I] = newValue; 
                } 
            } 
        } 
        /// <summary> 
        position specified /// returns an array of the total of the first occurrence 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "value" > </ param> 
        /// <Returns> </ Returns>      
        static int indexOf (int [] ARR, int value) 
        { 
            { 
                // if else behind when only one statement may be no brackets 
                // If found equal to the value of an external number, then returns the index 
                IF (ARR [I] == value) I return;                 
            } 
            // query if not, returns -1; 
                return -1;               
        } 
        /// <Summary> 
        /// returns the value specified in the array, the position of the last occurrence 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "value"> </ param> 
        static int lastIndexOf (int [] ARR, int value) 
        { 
            // by reverse thinking, a reciprocal of the first, the last positive 
            for (int i = arr.Length - 1 ; i> = 0;i--)
            {
                if(arr[i] == value)
                {
                    // this function is performed directly back to the 
                    IF (ARR [J]>
                    I return; 
                } 
            } 
            // because the array index starts from 0. 
            return -1; // return a positive integer are any unreasonable        
        } 
        /// <Summary> 
        /// array elements, arranged in ascending 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        static void fromMintoMax (int [] ARR) 
        { 
            // the number of exchanges: two cycles should be around 
            for (int I =. 1; I <arr.length -. 1; I ++) 
            { 
                for (int J = 0; J <arr.length - I; J ++) 
                { 
                    int T; 
                    { 
                        T = ARR [J]; 
                        ARR [J] = ARR [J +. 1]; 
                        ARR [J +. 1] = T; 
                    } 
                } 
            } 
 
        } 
        /// <Summary> 
        certain period value /// Remove the specified array, to remove from the specified index subscript specified 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "sindex"> start position to start deleting </ param> 
        /// <param name = "eIndex"> delete end position, but the value of the end position </ param> does not include 
        static void deletekinddata (int [] ARR, sindex int, int Eindex) 
        { 
            // do not include the last one, it is eIndex> arr.Length. Analyzing 
            if (sIndex <0 || eIndex> arr.
            for (int J = Eindex; J <arr.length; J ++) 
            { 
                ARR [TEMP] = ARR [J]; 
                // ARR [sindex] = ARR [J]; sindex value is not changed 
                TEMP ++; 
                // sindex ++ ; if used directly, its value is changed, the assignment cycle can not be used normally 
            } 
            // determine the number of cleared, and thus assigned the value 0. 
            for (int X =-arr.length. 1; X> = arr.Length- (Eindex-sindex); x--) 
            { 
                ; ARR [X] = 0 
            } 
        } 
        /// <Summary> 
        element end /// still deleted. 
        /// </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "sindex"> </ param>
        void deletekinddata2 static (int [] ARR, sindex int, int Eindex) 
        { 
            IF (Eindex <0 || sindex> arr.length) return; 
            // I: indicates the number to be deleted 
            for (int i = 0; i < sindex-Eindex; I ++) 
            { 
                // deletespecificSUB: delete the specified index; after deleting a number of array values will be moved one space forward. 
                // then should be deleted location sindex 
                deletespecificSUB (ARR, sindex); 
            } 
        } 



        /// <Summary> 
        /// Remove the specified value of the number array, removed from the specified location, deletes the specified number of future 
        // / </ Summary> 
        /// <param name = "ARR"> </ param> 
        /// <param name = "sindex"> delete start position </ param> 
        /// <
        static void deletecountdata(int[]arr,int sIndex, int Length)
        {
            for(int i =0; i < arr.Length; i++)
            {
                 for(int j=sIndex + Length - 1;j >= sIndex;j--)
                {
                    //arr[j] = 0;
                    for(int x= sIndex + Length - 1;x< arr.Length-1; x++)
                    {
                        int t;
                        t= arr[x + 1];
                        arr[x + 1] = arr[x];
                        arr[x] = t;
                    }
                }
                 
              
            }
            for(int y = arr.Length - 1; y >= arr.Length - Length; y--)
            { 
                ARR [Y] = 0; 
            } 
        }          
        // show all of the elements in the array of 
        static void arrshow (int [] arr ) // an incoming parameters define the type 
        { 
            for (int I = 0; I <arr.length ; I ++) 
            { 
                Console.Write (ARR [I] + ""); 
            }   
        } 
         
    } 
}

  

Guess you like

Origin www.cnblogs.com/allyh/p/11456430.html