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. 2 3139
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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#...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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);"...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |