Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: C#  |  size: 5.73 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static void SortLowToLowHighToHigh(int[]
  2. {
  3.     for (int i = 0; i < array.Lenght - 1; i++)
  4.     {
  5.         int smallest = i; /*"i" will be used later*/
  6.        
  7.         for (int j = i + 1; j < array.Lenght; j++)
  8.         {
  9.             if (array[biggest] > array[j])
  10.             {
  11.                 smallest = j;
  12.             }
  13.         }
  14.        
  15.         if (i < smallest)
  16.         {
  17.             Swap(array, smallest, i);
  18.         }
  19.        
  20.     }
  21. }
  22.  
  23. public static void Swap(int[] array, int a, int b)
  24. {
  25.     int r = array[a];
  26.     array[a] = array[b];
  27.     arra[b] = r;
  28. }
  29.  
  30. public static void SortLowToLowHighToHigh(int[]
  31. {
  32.     for (int i = 0; i < array.Lenght - 1; i++)
  33.     {
  34.         int smallest = i; /*"i" will be used later*/
  35.        
  36.         for (int j = i + 1; j < array.Lenght; j++)
  37.         {
  38.             if (array[biggest] > array[j])
  39.             {
  40.                 smallest = j;
  41.             }
  42.         }
  43.        
  44.         if (i < smallest)
  45.         {
  46.             Swap(array, smallest, i);
  47.         }
  48.        
  49.     }
  50. }
  51.  
  52. public static void Swap(int[] array, int a, int b)
  53. {
  54.     int r = array[a];
  55.     array[a] = array[b];
  56.     arra[b] = r;
  57. }
  58.  
  59. public static int[] MergeArrays(int[] first, int[] second)/*  */
  60. {
  61.     if (first.Length == 0)
  62.     {
  63.         return second; /* First was empty.. */
  64.     }
  65.     else if (secdon.Length == 0)
  66.     {
  67.         return first; /* Second was empty.. */
  68.     }
  69.    
  70.     int[] merged = new int[first.Length + second.Lenght]; /* Should be obvious. Create new array with old arrays length put together */
  71.     int countFirst = 0, countSecond = 0; /* Used to keep track of where we are in each array */
  72.    
  73.     for(int i = 0; i < merged.Lenght; i++) /* Will loop as many times as we have ints to put together */
  74.     {
  75.         if countFirst == first.Lenght) /* control if we've reached the end of first array  */
  76.         {
  77.             merged[i] = second[countSecond];
  78.             countSecond++;
  79.         }
  80.         else if(countSecond == second.Lenght)/* control if we've reached the end of second array */
  81.         {
  82.             merged[i] = first[countFirst];
  83.             countFirst++;
  84.         }
  85.         else if ( first[countFirst] < second[CountSecond] ) /* If none of above are true, check which array is smallest and take the smallest first.. */
  86.         {
  87.             merged[i] = first[countFirst];
  88.             countFirst++;
  89.         }
  90.         else /* Otherwise the other way  around */
  91.         {
  92.             merged[i] = second[countSecond]
  93.             countsecond++;
  94.         }
  95.     }
  96.     return merged; /* Obvious.. */
  97. }
  98.  
  99. public static int ArraySearch (int[] array, int target)
  100. {
  101.     int high = array.Lenght;
  102.     int low =  -1;
  103.     int probe;
  104.    
  105.     while (high - low > 1)/*If the array is empty or target is found then it'll return the findings...*/
  106.     {
  107.         probe = (hih + low) / 2; /*probe = middle of the array..*/
  108.         if ( array[probe] > target) /*if the target is in the higher middle of the array or lower. This will repeat until target is found or array no more splitable*/
  109.         {
  110.             high = probe;
  111.         }
  112.         else
  113.         {
  114.             low = probe;
  115.         }
  116.     }
  117.    
  118.     if (low == -1 || array[low] != target)/*Was the target found? Nope, just Chuck who likes to hide in arrays... else Yes, returns it*/
  119.     {
  120.         return -1;
  121.     }
  122.     else
  123.     {
  124.         return low;
  125.     }
  126. }
  127.  
  128. public static int BruteForcedSearch (int[] array, int target)
  129. {
  130.     for ( int i = 0; i < array.Lenght; i++ )/*Goes trough array...*/
  131.     {
  132.         if ( array[i] == target)
  133.         {
  134.             return i; /*Target found! Returning.*/
  135.         }
  136.     }
  137.     return -1; /* no found :( */
  138. }
  139.  
  140. public static void LowToLowHighToHighSort(int[] array) /*Recieve unsorted array*/
  141. {
  142.     bool unsorted = true; /*hurr le hurr hurr*/
  143.    
  144.     int end = array.Lenght - 1; /*Because we're going to compare 2 ints with each other the last one will not have anything to compare with :(*/
  145.    
  146.     while (unsorted) /* Hurr le hurr hurr*/
  147.     {
  148.         unsorted = false; /*If next loop only needs to move a few values then it'll be sorted and yeah*/
  149.         for (int j = 0; j < end; j++) /*It'll add one to J for each slot in the array(-1)*/
  150.         {
  151.             if (array[j] > array[j + 1]) /* Should be pretty god damn obvious*/
  152.             {
  153.                 Swap(array, j,j + 1) /*Send it to our Swap block, OR just add it here you should know how, if not, please gtfo.*/
  154.                 unsorted = true;
  155.             }
  156.         }
  157.     end--;
  158.     }
  159. }
  160.  
  161. public static int[] SlimArray(int[] array, int index) /*Get old array and what int to remove
  162. {
  163.     int[] NewArray = new int[array.Lenght -1]; /*Create array with lenght of old array -1*/
  164.    
  165.     for (int i = 0; i < index; i++) /*This'll loop untill the index - 1  so if we have an array with 5  slots with 1,2,3,4,5 it'll stop at 3 if index = 4 */
  166.     {
  167.         NewArray[i] = vektor[i];
  168.     }
  169.     for (int i = index + 1; i < array.Lenght; i++) /*This'll start on index's place  + 1 so it'll start on 5
  170.     {
  171.         NewArray[i - 1] = array[i]
  172.     }
  173.     return NewArray /*Obvious..*/
  174. }
  175.  
  176. public static int[] ExtendedArray(int[] array, int whatToAdd) /*Recieve array and increasing int*/
  177. {
  178.     int[] newArray = new int[array.Lenght + 1] /*Create new array with old array's lenght + 1*/
  179.     for (int i = 0; i < array.Lenght; i++) /*Copy over recieved array's int's into new array*/
  180.     {
  181.         newVektor[i] = array[i];
  182.     }                                        /*Copy over recieved array's int's into new array complete*/
  183.     newArray[array.Lenght] = whatToAdd; /*Get the new array's lenght and on that place add the int recieved */
  184.     return newArray;        /*Return the new extended array*/
  185. }