473,385 Members | 1,736 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.

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 3140
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
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
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
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
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
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
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
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
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
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
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
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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,...

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.