473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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==nu ll)
{
ArvorePonteiro obj = new ArvorePonteiro( 1);
novoNo->noEsquerdo =&obj;
Inserir(ref novoNo->noEsquerdo,r ef valor);
}
else
{
Inserir(ref novoNo->noEsquerdo,r ef valor);
}
}
else
{
if (novoNo->noDireito==nul l)
{
ArvorePonteiro teste = new ArvorePonteiro( 1);
novoNo->noDireito=&tes te;
Inserir(ref novoNo->noDireito,re f valor);
}
else
{
Inserir(ref novoNo->noDireito,re f valor);
}
}
}

}
public unsafe void PreOrdem(Arvore Ponteiro* novoNo)
{
if (novoNo->vazio==false )
{
Console.WriteLi ne(novoNo->valor);
PreOrdem(novoNo->noEsquerdo);
PreOrdem(novoNo->noDireito);
}
}
}
}

Nov 16 '05 #1
1 2178
Tiago <Ti***@discussi ons.microsoft.c om> 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.co m>
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
5299
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 pointer to the parent node, the program will be inefficient and slow. It works fine at first. However, when I started to build the remove function, it destroys the tree when I delete a node. I already changed the parent pointer whenever I delete a...
5
9561
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
1972
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 something to do with dynamic data object ? thanx for your help. ================== begin of code ============================== #include <stdio.h> #include <stdlib.h>
15
5085
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 lists. I'm totally new to binary searches by the way. Can anyone help me with the commented sections below? Much of the code such as functions and printfs has already been completed. Any help is greatly appreciated. Thanks,
1
3506
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') AND ( Type = 'Text' ) ) OR ( Loc = '123' ) I envisioned a binary tree, and using a stack object, I'd parse through the statement to populate the tree to something like this. (hope it looks right
3
3527
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 objects of the Node class. I have a function addNode which is defined as follows void Bstree::addNode ( Node **start, int val ) { if( *start == NULL ) //if bst empty { *start = new Node ( val );
3
6541
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, and build a binary search tree from the new list. But this seems to be expensive in terms of space. Can this be done more efficiently ? Please help me.
8
7813
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
11006
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 into an infinite loop, i think im messing up with the pointers. Heres the code. //press 1, first, Do not press it a second time!!!
0
8246
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7174
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.