// Works only with comutative operation ( ex: *, + ) public static void Main() { var binaryIndexedTree = new BinaryIndexedTree <int>(30, (a, b) => { return(a * b); }); for (int i = 0; i < 10; i++) { binaryIndexedTree[i] = i; } Console.WriteLine(binaryIndexedTree.GetInterval(0, 5)); Console.WriteLine(binaryIndexedTree.GetInterval(6, 10)); Console.WriteLine(binaryIndexedTree.GetInterval(3, 7)); }
public static void Main() { //var tree = new TreeNode<int>(20, // new TreeNode<int>(44, // new TreeNode<int>(17), new TreeNode<int>(41)), // new TreeNode<int>(02, // new TreeNode<int>(99), new TreeNode<int>(97))); // DFS(tree); // BFS(tree); //DFSWithStack(tree); //var array = new int[10]; //var random = new Random(); //for (int i = 0; i < array.Length; i++) //{ // array[i] = random.Next() % 100; //} //Console.WriteLine(string.Join(" ", array)); //var heap = new BinaryHeap.BinaryHeap<int>((a, b) => a > b); //foreach (var element in array) //{ // heap.Insert(element); // Console.Write(heap.GetTop() + " "); //} //Console.WriteLine(); //for (int i =0; i < array.Length; i++) //{ // array[i] = heap.GetTop(); // heap.RemoveTop(); //} //Console.WriteLine(string.Join(" ", array)); //var array = new int[10]; //var random = new Random(); //for (int i =0; i < array.Length; i++) //{ // array[i] = random.Next() % 100; //} //array.HeapSort((a, b) => a > b); var list = new List <int>(); list.Add(3); list.Add(4); list.Add(5); var indexedTree = new BinaryIndexedTree <int>(list, (a, b) => a + b); Console.WriteLine(indexedTree.GetInterval(0, 3)); }