473,503 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structure

I'd like to make a tree without any functions. I mean just using the
structure.
I have a structure:
struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{

??????????
}

In the place with quastions I should write something for making a
tree. (Any tree). I just need to know how is it possible. I wrote
something like
struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{
5, Tree[3], Tree[6],
4, NULL, NULL,
6, NULL, NULL
}
It didn't work.
Nov 13 '05 #1
2 3151
maths_fan wrote:
struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{
5, Tree[3], Tree[6],
4, NULL, NULL,
6, NULL, NULL
}
It didn't work.


struct TTree { ... };
static struct TTree node4 = { 4, NULL, NULL }, node6 = { 6, NULL, NULL };
static struct TTree node5 = { 5, &node4, &node6 };
struct TTree *Tree = &node5;

This is assuming you want your Tree variable to be a pointer and not the
root node itself. I.e. if you want to be able to change which node is
the root node. Otherwise you could rename node5 to Tree.

--
Hallvard
Nov 13 '05 #2
maths_fan wrote:
I'd like to make a tree without any functions. I mean just using the
structure.
I have a structure:
struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{

??????????
}

In the place with quastions I should write something for making a
tree. (Any tree). I just need to know how is it possible. I wrote
something like
struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{
5, Tree[3], Tree[6],
4, NULL, NULL,
6, NULL, NULL
}
It didn't work.


Nit picking: How do you print it without any functions?

Try this:
#include <stdio.h>

struct TTree
{
int key;

struct TTree* pLeft;
struct TTree* pRight;
} Tree[] =
{
/* Tree[0] */ 5, &Tree[1], &Tree[2],
/* Tree[1] */ 4, NULL, NULL,
/* Tree[2] */ 6, NULL, NULL
};

int main(void)
{
puts("Tree Program");
return 0;
}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 13 '05 #3

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

Similar topics

2
11930
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
4
3877
by: marco_segurini | last post by:
Hi, From my VB program I call a C++ function that gets a structure pointer like parameter. The structure has a field that contains the structure length and other fields. My problem is that...
8
3311
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. ...
15
8184
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
3
8878
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
14
1765
by: Dennis | last post by:
If I have a structure like; Public Structure myStructureDef Public b() as Byte Public t as String End Structure If I pass this structure, will the values in the array b be stored on the...
10
4967
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
11
1905
by: Lance | last post by:
Hi all, I've got a some structures defined as ////// <StructLayout(LayoutKind.Sequential)Public Structure GM_LayerInfo_t Public mDescription As String Public mNativeRect As GM_Rectangle_t...
4
1707
by: eBob.com | last post by:
In my class which contains the code for my worker thread I have ... Public MustInherit Class Base_Miner #Region " Delegates for accessing main UI form " Delegate Sub DelegAddProgressBar(ByVal...
5
3773
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
7203
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
7087
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
7281
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
7334
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...
1
6993
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...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5579
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
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
737
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.