/// ///////////////////////////////////////////////////////////////////////////////////////////////// public void deleteKey() { System.Console.WriteLine("Silinecek Değeri giriniz:"); int anektar = Convert.ToInt32(System.Console.ReadLine()); rootNode = deleteRec(rootNode, anektar); }
public int minValue(bstNodeC root) { int minv = root.sayi; while (root.leftNode != null) { minv = root.leftNode.sayi; root = root.leftNode; } return(minv); }
public void siralayiver(bstNodeC aktif) { listBox1.Items.Add(aktif.sayi); if (aktif.leftNode != null) { siralayiver(aktif.leftNode); } if (aktif.rightNode != null) { siralayiver(aktif.rightNode); } }
public void max_bul(bstNodeC node) { if (node.sayi == 0) { lavel2.Text = Convert.ToString(node.sayi); } else if (node.rightNode != null) { max_bul(node.rightNode); } else { lavel2.Text = Convert.ToString(node.sayi); } }
public void min_bul(bstNodeC node) { if (node.sayi == 0) { lavel1.Text = Convert.ToString(node.sayi); } else if (node.leftNode != null) { min_bul(node.leftNode); } else { lavel1.Text = Convert.ToString(node.sayi); } }
private void Form1_Load(object sender, EventArgs e) { listBox1.Items.Add(rootNode.sayi); bstNodeC yeni = new bstNodeC(15, null, null); rootNode.leftNode = yeni; yeni = new bstNodeC(35, null, null); rootNode.rightNode = yeni; if (rootNode.leftNode != null) { listBox1.Items.Add(rootNode.leftNode.sayi); } if (rootNode.rightNode != null) { listBox1.Items.Add(rootNode.rightNode.sayi); } }
public bstNodeC deleteRec(bstNodeC root, int key) { /* Base Case: If the tree is empty */ if (root == null) { return(root); } /* Otherwise, recur down the tree */ if (key < root.sayi) { root.leftNode = deleteRec(root.leftNode, key); } else if (key > root.sayi) { root.rightNode = deleteRec(root.rightNode, key); } // if key is same as root's key, then This is the node // to be deleted else { // node with only one child or no child if (root.leftNode == null) { return(root.rightNode); } else if (root.rightNode == null) { return(root.leftNode); } // node with two children: Get the // inorder successor (smallest // in the right subtree) root.sayi = minValue(root.rightNode); // Delete the inorder successor root.rightNode = deleteRec(root.rightNode, root.sayi); } return(root); }
/* A recursive function to insert a new key in BST */ public bstNodeC insertRec(bstNodeC root, int key) { /* If the tree is empty, return a new node */ if (root == null) { root = new bstNodeC(key, null, null); return(root); } /* Otherwise, recur down the tree */ if (key < root.sayi) { root.leftNode = insertRec(root.leftNode, key); } else if (key > root.sayi) { root.rightNode = insertRec(root.rightNode, key); } /* return the (unchanged) node pointer */ return(root); }
private void ekleyiver(int sayi, bstNodeC node) { bstNodeC yeniNode = new bstNodeC(sayi, null, null); if (node.sayi == 0 || node == null) { node.sayi = sayi; } else { bstNodeC current = node; bstNodeC parent; while (true) { parent = current; if (sayi < current.sayi) { current = current.leftNode; if (current == null) { parent.leftNode = yeniNode; break; } } else { current = current.rightNode; if (current == null) { parent.rightNode = yeniNode; return; } } } } }
public bstNodeC(int sayi, bstNodeC leftNode, bstNodeC rightNode) { this.sayi = sayi; this.leftNode = leftNode; this.rightNode = rightNode; }
// This method mainly calls insertRec() public void insert(int key) { rootNode = insertRec(rootNode, key); }