Regarding a query related to References

S

skishorev

I am implementing a binary search tree. But, Here some of the nodes i
need to maintain a backup of .

This backup i am maintaining a Linked Lists.

Example: By using 1 to 100 numkbers i need to construct a binary
search tree.
In this some numbers
1 4 5 7 8 50 (random numbers) to be in one linked
list
2 3 8 9 (random numbers other than linked
list1) to be in second linked list.

At this time , How to i implement the same? How to i give the node
reference to both linked list and binary serach tree?

If you know can you please help me.
 
B

BubbaGump

I am implementing a binary search tree. But, Here some of the nodes i
need to maintain a backup of .

This backup i am maintaining a Linked Lists.

Example: By using 1 to 100 numkbers i need to construct a binary
search tree.
In this some numbers
1 4 5 7 8 50 (random numbers) to be in one linked
list
2 3 8 9 (random numbers other than linked
list1) to be in second linked list.

At this time , How to i implement the same? How to i give the node
reference to both linked list and binary serach tree?

If you know can you please help me.


typedef struct _Node {
struct _Node *list_back, *list_for;
struct _Node *tree_left, *tree_right;
} Node;


?
 
K

Keith Thompson

BubbaGump writes:
[...]
typedef struct _Node {
struct _Node *list_back, *list_for;
struct _Node *tree_left, *tree_right;
} Node;

Identifiers starting with an underscore and an uppercase letter are
reserved to the implementation. It's best to avoid declaring any
identifiers starting with an underscore.

If you insist on creating a second name for something that already has
one, there's no need to use two different identifiers:

typedef struct Node {
struct Node *list_back, *list_for;
struct Node *tree_left, *tree_right;
} Node;

Or you can just drop the typedef altogether:

struct Node {
struct Node *list_back, *list_for;
struct Node *tree_left, *tree_right;
};

and refer to the type as "struct Node".
 
S

skishorev

Can you please explain biefly.

At the time of constructing a binary search tree, shall i take the
references of particular nodes to Linked list1 or to Linked List2.
 
B

BubbaGump

BubbaGump writes:
[...]
typedef struct _Node {
struct _Node *list_back, *list_for;
struct _Node *tree_left, *tree_right;
} Node;

Identifiers starting with an underscore and an uppercase letter are
reserved to the implementation. It's best to avoid declaring any
identifiers starting with an underscore.

Really? Damn. You people really know the language details. You know
how many structs I've seen declared like this in both Windows and
Linux.

If you insist on creating a second name for something that already has
one, there's no need to use two different identifiers:

typedef struct Node {
struct Node *list_back, *list_for;
struct Node *tree_left, *tree_right;
} Node;

The leading underscore is a common convention. Geez. I need to get
out of this f***ing group.
 
K

Keith Thompson

BubbaGump said:
BubbaGump writes:
[...]
typedef struct _Node {
struct _Node *list_back, *list_for;
struct _Node *tree_left, *tree_right;
} Node;

Identifiers starting with an underscore and an uppercase letter are
reserved to the implementation. It's best to avoid declaring any
identifiers starting with an underscore.

Really? Damn. You people really know the language details. You know
how many structs I've seen declared like this in both Windows and
Linux.

Yes really. You're very likely to get away with it most of the time,
but the next version of your implementation is free to define a macro
"_Node" in a standard header, breaking your code.
The leading underscore is a common convention. Geez. I need to get
out of this f***ing group.

Not sure what you mean by that.

If you say the leading underscore is a common convention, you may be
right -- but it's a *bad* common convention.
 
B

Ben Pfaff

BubbaGump said:
BubbaGump writes:
[...]
typedef struct _Node {
struct _Node *list_back, *list_for;
struct _Node *tree_left, *tree_right;
} Node;

Identifiers starting with an underscore and an uppercase letter are
reserved to the implementation. It's best to avoid declaring any
identifiers starting with an underscore.

Really? Damn. You people really know the language details. You know
how many structs I've seen declared like this in both Windows and
Linux.

I've seen identifiers _Likethis declared like this in system
header files, but that's because system header files *need* to
use identifiers in the reserved namespace for many purposes.

I'm a little baffled about what's considered part of the
"implementation" under Windows. Perhaps they use those
identifiers where they believe they're writing part of the
implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top