473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Correct my c# program.

2
Hi
please correct program Binary Tree
Expand|Select|Wrap|Line Numbers
  1.  class TreeNode
  2.     {
  3.         private int dataValue;
  4.         private TreeNode leftNode = null;
  5.         private TreeNode rightNode = null;
  6.  
  7.         public TreeNode(int data)
  8.         {
  9.             dataValue = data;
  10.         }
  11.         public TreeNode LeftNode
  12.         {
  13.             get
  14.             {
  15.                 return leftNode;
  16.             }
  17.             set
  18.             {
  19.                 leftNode = value;
  20.             }
  21.         }
  22.         public TreeNode RightNode
  23.         {
  24.             get
  25.             {
  26.                 return rightNode;
  27.             }
  28.             set
  29.             {
  30.                 rightNode = value;
  31.             }
  32.         }
  33.         public int DataValue
  34.         {
  35.             get
  36.             {
  37.                 return dataValue;
  38.             }
  39.             set
  40.             {
  41.                 dataValue = value;
  42.             }
  43.         }
  44.  
  45.  
Eror is root null.
Expand|Select|Wrap|Line Numbers
  1. class Program
  2.     {
  3.  
  4.  
  5.         static void Main(string[] args)
  6.         {
  7.  
  8.             Tree node = new Tree();
  9.             TreeNode T = new TreeNode(0);
  10.             create(T, 1);
  11.             Console.WriteLine();
  12.             Console.ReadLine();
  13.         }
  14.         public TreeNode create(TreeNode root, int dataValue)
  15.         {
  16.  
  17.             if (root == null)
  18.             {
  19.                 if (root == null)
  20.                 { return null; }
  21.                 else if (root.DataValue == dataValue)
  22.                 { return root; }
  23.                 else if (root.DataValue < dataValue)
  24.                 { return create(root.RightNode, dataValue); }
  25.                 else
  26.                 {
  27.                     return create(root.LeftNode, dataValue);
  28.                 }
  29.  
  30.             }
  31.  
  32.         }
  33.     }
  34.  
Dec 26 '10 #1
0 1180

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew | last post by:
Hi all , i am supposed to create a program that performs a specific operation to a 2-D matrix whose elements are positive (or zero ). This operation is repeated T times on the matrix and only the...
54
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
6
by: Alex Buell | last post by:
#include <vector> #include <algorithm> #include <iostream> using namespace std; template <typename T> class LessThan { private:
3
by: wuzertheloser | last post by:
The correct program should look like this: Total number of voting cards: 55 Votes for candidate 1: 1 Votes for candidate 2: 10 Votes for candidate 3: 8 Votes for candidate 4: 13 Votes...
4
by: alisbub | last post by:
1. Write an interactive program that asks the user to input the length and width of a rectangular lawn. The dimensions should be in yards. Your program should compute the area of the lawn in square...
14
by: Army1987 | last post by:
The following program compiles without errors or warnings with gcc -ansi -pedantic and works properly. #include <string.h> #include <stdlib.h> #include <stdio.h> char *f(char *str1, char...
73
by: Rajeet Dalawal | last post by:
Good day group. I was asked in an interview to explain the behavior of this program. void main() { char *s = "abc"; int *i = (int *) s; printf("%x", *i); }
24
by: lector | last post by:
#include <stdio.h> #include <math.h> #define M_PI 3.14159 int main(void) { double theta, phi, sinth; double count; double incr; double s;
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.