473,385 Members | 1,396 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,385 software developers and data experts.

Binary Tree with Pointers

I´m doing a paper about Binary Tree with pointers, and a want to reproduce them in C# but I must use pointers .I Tried to do but failed . My piece of code (with pointers)
not Working(I can´t use class , anyone know why?):
I did it without pointers , but i can´t use it for my paper.

Thank you for any help

namespace Arvores
{
public unsafe struct ArvorePonteiro
{
private int valor;
private unsafe ArvorePonteiro* noEsquerdo;
private unsafe ArvorePonteiro* noDireito;
private bool vazio;

public unsafe ArvorePonteiro(int cheio)
{
vazio=true;
valor=0;
this.noDireito=null;
this.noEsquerdo=null;
}

public unsafe void Inserir(ref ArvorePonteiro* novoNo,ref int valor)
{
if (novoNo->vazio==true)
{
novoNo->valor=valor;
vazio=false;
}
else
{
if (valor < novoNo->valor)
{
if (novoNo->noEsquerdo==null)
{
ArvorePonteiro obj = new ArvorePonteiro(1);
novoNo->noEsquerdo =&obj;
Inserir(ref novoNo->noEsquerdo,ref valor);
}
else
{
Inserir(ref novoNo->noEsquerdo,ref valor);
}
}
else
{
if (novoNo->noDireito==null)
{
ArvorePonteiro teste = new ArvorePonteiro(1);
novoNo->noDireito=&teste;
Inserir(ref novoNo->noDireito,ref valor);
}
else
{
Inserir(ref novoNo->noDireito,ref valor);
}
}
}

}
public unsafe void PreOrdem(ArvorePonteiro* novoNo)
{
if (novoNo->vazio==false)
{
Console.WriteLine(novoNo->valor);
PreOrdem(novoNo->noEsquerdo);
PreOrdem(novoNo->noDireito);
}
}
}
}

Nov 16 '05 #1
1 2163
Tiago <Ti***@discussions.microsoft.com> wrote:
I?m doing a paper about Binary Tree with pointers, and a want to
reproduce them in C# but I must use pointers .I Tried to do but
failed . My piece of code (with pointers)
not Working(I can?t use class , anyone know why?):
I did it without pointers , but i can?t use it for my paper.


What do you mean by "I can't use class"?

Using a reference type often accomplishes what you might use pointers
for in C.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dannielum | last post by:
Hi all, I am trying to write a Binary Search Tree that each of its node will have 3 node pointers: left, right and parent. I need a parent pointer for some the purpose of my project. Without the...
5
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
7
by: sugaray | last post by:
the binary search tree node here contains another structure as it's data field, programs did successfully work when data field is int, char, this time i got stucked, don't know why ? if there's...
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
1
by: Daniel Bass | last post by:
Using VC#.Net, I want to take a statement, that loosely follows the rules of an SQL'a "WHERE" statement, and determine whether that statement is true or false. For example: ( ( Head = 'abc')...
3
by: Nick Kiguta | last post by:
I have two classes, a Node class and a Bstree class. The Bstree class contains a pointer to a Node class as one of its private members. Now I need to build a binary search tree from multiple...
3
by: ptrSriram | last post by:
Can someone help me with an algorithm to merge two binary search trees. One method I thought of was to flatten both the trees into sorted lists(inorder traversal),merge those two sorted lists,...
8
by: sudharsan | last post by:
please gimme the logic to merge two binary search trees?I mean which node has to be the root node of the new binary tree?? Thanks in advance
4
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.