Skip to main content

Posts

Showing posts from December, 2016

Introduction To C++ Programming - Part 4.

C++ Program To Calculate Determinant Of A Matrix #include<iostream> #include<math.h> using namespace std; double d = 0; double det(int n, double mat[10][10]); double det(int n, double mat[10][10]){ double submat[10][10]; if (n == 2) // set the matrix (must be square) to find determinant. return ((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1])); else { for (int c = 0; c < n; c++) { int subi = 0; for (int i = 1; i < n; i++) { int subj = 0; for (int j = 0; j < n; j++) { if (j == c) continue; submat[subi][subj] = mat[i][j]; subj++; } subi++; } d = d + (pow(-1, c) * mat[0][c] * det(n - 1, submat)); }} return d; }

Java Program To Implement Red Black Tree Operations.

import java.util.Scanner; public class RedBlackTreeA { public static void main(String[] args) { Scanner scan = new Scanner(System.in); RBTree rbt = new RBTree(Integer.MIN_VALUE); char ch; do {       // Deletion of Nodes is not implemented. System.out.println("Red Black Tree Operations:"); System.out.println("1. Insert "); System.out.println("2. Search"); System.out.println("3. Count Nodes"); System.out.println("4. Check Empty"); System.out.println("5. Clear Tree\n"); System.out.print("Enter Your Choice: "); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.print("Enter An Integer To Insert: "); rbt.insert( scan.nextInt() ); break; case 2 : System.out.print("Enter An Integer To Search: "); System.out.println("Search Result : "+ rbt.search( scan.nextInt() )); break;

Java Program To Implement Self-Balancing Binary Search Tree.

import java.util.Scanner; class SBBSTNode { SBBSTNode left, right; int data; int height; public SBBSTNode() { left = null; right = null; data = 0; height = 0; } public SBBSTNode(int n) { left = null; right = null; data = n; height = 0; }} class SelfBalancingBST { private SBBSTNode root;     public SelfBalancingBST() { root = null; } public boolean isEmpty() { return root == null; }