C++ :: Binary Search Delete Function
Nov 26, 2013
I am having an issue when i try to delete a node with 2 children it either doesn't delete anything, or wigs out in various manners deleting the wrong node or replacing a node with a various memory location. As follows, here is the delete function:
void BST::dele(){
bool found = false;//initialize a bool type to "find" the element to be deleted
if(root == NULL) return;//well if the tree's empty, nothing to be found right?
current = root;//set the current to the root to traverse the tree in search of the element
node* parent;//create a parent node for use once the node has been deleted
while(current != NULL){//traverse the tree
[Code] .....
View 1 Replies
ADVERTISEMENT
Apr 1, 2014
I had an assignment that I completed and it was just inserting values into a binary tree and then displaying it. I was wondering what the code would be if I wanted to delete a number in the binary tree, or if I wanted to search for a number. Here is my code for my assignment.
Code:
#include <stdio.h>
#include<stdlib.h>
typedef struct bt_{
int value;
struct bt_ *right;
struct bt_ *left;
[Code] ....
View 1 Replies
View Related
Apr 3, 2013
This is the delete function of binary search tree. However it won't enter the if-else statement that checks whether the node to be deleted is the left child or right child.
void DeleteNode(node* T, int number) {
node* x = new node;
node* current = new node;
node* dele = new node;
node* finder = new node;
finder = root;
[Code] ....
View 2 Replies
View Related
Sep 5, 2014
Below is my implementation of a Binary Search Tree, but there is a bug in the DeleteNode() function. It does not set the parent's pointer to NULL as I intended.
View 1 Replies
View Related
Jun 21, 2013
I'm trying to add a search and delete function to my program
#include <Windows.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
class Cvampire{
[Code] ....
View 4 Replies
View Related
Aug 17, 2013
I want to create a function to Delete , Edit record of Bianry File in C++, I have tried again and gain but not success .
View 1 Replies
View Related
Feb 14, 2014
Im working on a BST remove function. I think I'm on the right track but I'm not sure. From what I understand there are 3 possible cases. A Node with no children, one child, or 2 children(this being the most complex).
void BST::remove(int x) {
TreeNode *n;
TreeNode *v;
n= root;
while(n != NULL && n->key != x){
[Code] ....
View 4 Replies
View Related
Nov 2, 2014
1) how come root node is printed when the first call to function goes to left subtree?
2) How it resets to root to go to right subtree from last left tree leaf?
void bst:: printNodes(hwareItem*& root){
if(root){
printNodes(root->left);
cout<<root->barcode<<endl;
cout<<root->description<<endl;
cout<<root->price_per_unit<<endl;
cout<<root->stock<<endl;
printNodes(root->right);}
}
View 19 Replies
View Related
Jun 23, 2013
I was studying BST and tried to make a iterative function to insert, the original recursive function is the following:
void insert(node *&tree, int value) {
if (!tree) {
tree = new node;
tree->num = value;
tree->left = tree->right = NULL;
[Code] ....
And the code that i did is (but doesn't work):
void insert(node *&tree, int value) {
if (!tree) {
tree = new node;
tree->num = value;
tree->left = tree->right = NULL;
[Code] ....
I don't see where the error is or why it doesn't work.
View 6 Replies
View Related
Nov 18, 2013
I am unable to implement the insert function properly, every time i run the program i just get the first value and name, I am not getting other Id's and name.
"(Header File)"
#include <iostream>
#include <string>
using namespace std;
class node{
public:
int ID;
string name;
class node *left, *right, *parent;
[Code] .....
View 4 Replies
View Related
Nov 18, 2013
I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.
Code:
"(Header File)"
#include <iostream>
#include <string>
using namespace std;
class node {
public:
int ID;
node (string StudentName, int IDNumber) {
[Code] ....
View 4 Replies
View Related
Nov 9, 2014
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)
[Code] ....
Why my code does not fulfill it's purpose???
View 7 Replies
View Related
Sep 16, 2013
Write a program to find the number of comparisons using the binary search and sequential search algorithms
//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;
[code]....
View 4 Replies
View Related
Oct 7, 2014
inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.
How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.
#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>
[Code].....
View 3 Replies
View Related
Apr 23, 2012
Just doing some work where i need to produce a database in C++ for DVD now I have done most of it but I'm stuck on some bits. I have split the database up into different files but I will post the files which are important. How to do a search function. I got told it's called "Bubble search" and then a delete function which i think is called "Vector delete".
My header file
Code:
#ifndef DVD_DB_H
#define DVD_DB_H
#include "dvd.h"
#include <vector>
class dvdDB {
private:
std::vector<DVD> dvds; // A container that contains an arry of DVDs
[Code] .....
View 1 Replies
View Related
Dec 9, 2014
I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).
idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.
The program detects OK when is the first in the list and when not, but it doesn't delete the node.
Code:
typedef struct bookingList{
tSpecialty specialty;
struct nodo* intro;
} tList;
[Code].....
View 7 Replies
View Related
Dec 23, 2013
I am trying to delete a node(has no children). for some reason, it keeps giving me an error.
void AVLtree<T>::remove(const T& item) {
node* curr = root;
node* prev = nullptr;
node* next = nullptr;
if(curr == nullptr)
[Code] .....
the error is: Access violation reading location 0xfeeefeee.
View 2 Replies
View Related
Jan 12, 2013
How To Delete A Record From binary File - C++ ?
View 1 Replies
View Related
Aug 12, 2014
It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.
Code:
void tree::search(int key,Node* leaf) {
if (leaf == NULL) {
std::cout<<"The tree is empty
[Code] ......
View 3 Replies
View Related
Oct 27, 2014
I am trying to implement BST using templates. This is the code that i have written.
Code: template <class T>
struct node
{
struct node *left;
[Code].....
There are no errors but the program hangs. What is the mistake with this program ?
View 2 Replies
View Related
Nov 22, 2013
Looking for the binary search program using c Graphics....
View 5 Replies
View Related
Oct 3, 2013
I'm trying to use the biSearch function to search for a keyword in the dictionary.
Code:
int biSearch(Dict DictEntries[MAXENTRIES],int start, int finish,char *keyword) {
int mid = (start+finish)/2;
int index = strcmp(DictEntries[mid].key,keyword);
printf("%s=%s
",DictEntries[mid].key,keyword);
[Code] ....
View 4 Replies
View Related
Apr 19, 2014
I am not sure how to use the parameters ostream and enum type in a print function.
enum TraversalOrderType {preorder, inorder, postorder};
template <class ItemType>
void Tree<ItemType>::print(ostream & Outstream, TraversalOrderType order) {
[Code] ....
Is this the correct way to call the print function?
int main() {
Tree<int> tree1;
tree1.print(cout, preorder);
return 0;
}
View 2 Replies
View Related
May 10, 2014
I don't know why, but my remove function doesn't seem to operate properly. The rest of my code is fine, so I am trying to pinpoint the exact location of my error. The else if statement remove(root->left, data) should've been called twice, but it only called once.
BST* smallestNode(BST* root)
// precondition: T is not null
// postcondition: return the node in the subtree rooted at T that
[Code]....
View 2 Replies
View Related
Apr 29, 2013
Traversal of binary search tree. In my header file there is a function setTraversal (public) and private print file. As I understood from teacher's explanation, my setTraversal function should call the recursive print function and print the list depending on selected order (pre,in or post-order). I still cannot get my head around what should be in setTraversal function definition. All resources I read last two days explain each order separately (preorder, inorder, postorder). How can I combine them? Here is my code:
#include "NodeTypeBST.h"
#include <iostream>
enum TravType {PRE, IN, POST};
template<class T>
class BST
[Code] ....
View 1 Replies
View Related
Jul 9, 2013
I was working on binary tree implementation and came up with this implementation. optimize this code?
/*
Binary Search Tree(BST)
06/27/2013
*/
#include "iostream"
[Code].....
View 3 Replies
View Related