public static void SortLowToLowHighToHigh(int[]
{
for (int i = 0; i < array.Lenght - 1; i++)
{
int smallest = i; /*"i" will be used later*/
for (int j = i + 1; j < array.Lenght; j++)
{
if (array[biggest] > array[j])
{
smallest = j;
}
}
if (i < smallest)
{
Swap(array, smallest, i);
}
}
}
public static void Swap(int[] array, int a, int b)
{
int r = array[a];
array[a] = array[b];
arra[b] = r;
}
public static void SortLowToLowHighToHigh(int[]
{
for (int i = 0; i < array.Lenght - 1; i++)
{
int smallest = i; /*"i" will be used later*/
for (int j = i + 1; j < array.Lenght; j++)
{
if (array[biggest] > array[j])
{
smallest = j;
}
}
if (i < smallest)
{
Swap(array, smallest, i);
}
}
}
public static void Swap(int[] array, int a, int b)
{
int r = array[a];
array[a] = array[b];
arra[b] = r;
}
public static int[] MergeArrays(int[] first, int[] second)/* */
{
if (first.Length == 0)
{
return second; /* First was empty.. */
}
else if (secdon.Length == 0)
{
return first; /* Second was empty.. */
}
int[] merged = new int[first.Length + second.Lenght]; /* Should be obvious. Create new array with old arrays length put together */
int countFirst = 0, countSecond = 0; /* Used to keep track of where we are in each array */
for(int i = 0; i < merged.Lenght; i++) /* Will loop as many times as we have ints to put together */
{
if countFirst == first.Lenght) /* control if we've reached the end of first array */
{
merged[i] = second[countSecond];
countSecond++;
}
else if(countSecond == second.Lenght)/* control if we've reached the end of second array */
{
merged[i] = first[countFirst];
countFirst++;
}
else if ( first[countFirst] < second[CountSecond] ) /* If none of above are true, check which array is smallest and take the smallest first.. */
{
merged[i] = first[countFirst];
countFirst++;
}
else /* Otherwise the other way around */
{
merged[i] = second[countSecond]
countsecond++;
}
}
return merged; /* Obvious.. */
}
public static int ArraySearch (int[] array, int target)
{
int high = array.Lenght;
int low = -1;
int probe;
while (high - low > 1)/*If the array is empty or target is found then it'll return the findings...*/
{
probe = (hih + low) / 2; /*probe = middle of the array..*/
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*/
{
high = probe;
}
else
{
low = probe;
}
}
if (low == -1 || array[low] != target)/*Was the target found? Nope, just Chuck who likes to hide in arrays... else Yes, returns it*/
{
return -1;
}
else
{
return low;
}
}
public static int BruteForcedSearch (int[] array, int target)
{
for ( int i = 0; i < array.Lenght; i++ )/*Goes trough array...*/
{
if ( array[i] == target)
{
return i; /*Target found! Returning.*/
}
}
return -1; /* no found :( */
}
public static void LowToLowHighToHighSort(int[] array) /*Recieve unsorted array*/
{
bool unsorted = true; /*hurr le hurr hurr*/
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 :(*/
while (unsorted) /* Hurr le hurr hurr*/
{
unsorted = false; /*If next loop only needs to move a few values then it'll be sorted and yeah*/
for (int j = 0; j < end; j++) /*It'll add one to J for each slot in the array(-1)*/
{
if (array[j] > array[j + 1]) /* Should be pretty god damn obvious*/
{
Swap(array, j,j + 1) /*Send it to our Swap block, OR just add it here you should know how, if not, please gtfo.*/
unsorted = true;
}
}
end--;
}
}
public static int[] SlimArray(int[] array, int index) /*Get old array and what int to remove
{
int[] NewArray = new int[array.Lenght -1]; /*Create array with lenght of old array -1*/
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 */
{
NewArray[i] = vektor[i];
}
for (int i = index + 1; i < array.Lenght; i++) /*This'll start on index's place + 1 so it'll start on 5
{
NewArray[i - 1] = array[i]
}
return NewArray /*Obvious..*/
}
public static int[] ExtendedArray(int[] array, int whatToAdd) /*Recieve array and increasing int*/
{
int[] newArray = new int[array.Lenght + 1] /*Create new array with old array's lenght + 1*/
for (int i = 0; i < array.Lenght; i++) /*Copy over recieved array's int's into new array*/
{
newVektor[i] = array[i];
} /*Copy over recieved array's int's into new array complete*/
newArray[array.Lenght] = whatToAdd; /*Get the new array's lenght and on that place add the int recieved */
return newArray; /*Return the new extended array*/
}