techn no

techn no

  • NA
  • 3
  • 6.3k

Error code

Aug 20 2005 3:08 AM
Hi guys! 

I encountered this error while trying to compile my application for BST using C# programming language,
Visual Studio.NET 2003. Could any programmers gurus enlighten me of such issue. Thanx!
The requirement of such implementation is to search a particular integer requested by a user.
If found ouput a msg to inform the user regarding the number of nodes visited and if there is
more than one node with the same value, return the results of all such nodes. Otherwsie ouptut
  
Error message : 'BST.BinarySearchTree.SearchNode(int)': not all code paths return a value

BSTSearchtree.cs

public BTNode SearchNode(int key) // the SearchNode method take in one

{ // argument.

BTNode current = root; // start at the root node

while(current.Data != key) // compare to see whether current

{

if(key < current.Data) // compare the key value with the value of the current node,

{ // if the key value is less than that value of the current node,

current = current.Left;

return current.Left; // it will move to the left of the subtree

}

else if(key > current.Data) // comapare the key value with the value of the current node again

{ // if the key value is more than the value of the current node,

current = current.Right;

return current.Right; // it will move to the right of the subtree

}

else if(key == current.Data) // compare the key value with value of the current node,

{ // if the key value is the same as the value of current

return current; // node, found it

}

if(current == null) // did not found any nodes

return null;

} // end while

} // end SearchNode


formBinarySearchtree

private void btnSearch_Click(object sender, System.EventArgs e)

{

BTNode node = bst.SearchNode(Convert.ToInt32(this.tbxNum.Text));

if(current.Data == key)

{

MessageBox.Show("Nodes found!");

}

MessageBox.Show((node.Key).ToString());

}

BTNode

using System;

namespace BST

{

public class BTNode

{

// attributes

private int key; //key to data

private int data;

private BTNode left; //reference to left child

private BTNode right; //reference to right child

// constructor

public BTNode(int k, int d)

{

key = k;

data = d;

}

//properties

public int Key

{

get

{

return key;

}

set

{

key = value;

}

}

public int Data

{

get

{

return data;

}

set

{

data = value;

}

}

public BTNode Left

{

get

{

return left;

}

set

{

left = value;

}

}

public BTNode Right

{

get

{

return right;

}

set

{

right = value;

}

}

} // end class BTNode

}