|
using System;
namespace TestDelegate
{
class Program
{
delegate void Sorter(ref int[] num);
static void BinarySort(ref int[] numbers)
{
//Some Codes to sort the array with Binary algoritm
//Finally, The array will be something like this :
numbers = new int[] { 0,1,2,3,4,5,6,7,8,9,10};
}
static void QuickSort(ref int[] numbers)
{
//Some Codes to sort the array with Quick algoritm
//Finally, The array will be something like this :
numbers = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
}
static void TreeSort(ref int[] numbers)
{
//Some Codes to sort the array with Tree algoritm
//Finally, The array will be something like this :
numbers = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
}
static bool SortAndSearch(ref int[] numbers, Sorter srt,int member)
{
srt(ref numbers);
foreach (int i in numbers)
if (i == member)
return true;
return false;
}
static void Main(string[] args)
{
int[] numbers = new int[] { 5, 9, 10, 3, 7, 2, 6, 1, 4, 8, 0 };
Console.WriteLine("Please Enter a method for Sorting\n (Binary/Quick/Tree)?");
//Consider Binary Search as default
Sorter sortIt = new Sorter(BinarySort);;
switch (Console.ReadLine().ToUpper())
{
case "QUICK":
sortIt = new Sorter(QuickSort);
break;
case "TREE":
sortIt = new Sorter(TreeSort);
break;
}
Console.WriteLine("Please Enter a Number to search");
if (SortAndSearch(ref numbers, sortIt, Convert.ToInt32(Console.ReadLine())))
Console.WriteLine("founded");
else
Console.WriteLine("Not Founde");
Console.ReadLine();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.