ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can someone please help ... I have an array and in this array each element contains a binary tree. How do i compare the string (same string) in the binary tree of array[1] with array[2]
array [1,2, ....]
eg;
array[1] array[2]
| |
root root
/ \ / \
left right left right
/ \ / \
... ... ... ...
/ \
hello hello
my declarations are like this:
typedef struct {
char *mystring;
}mydata;
and in my function
void myfunc(...){
mydata *p;
....
/* i'm stuck here */
....
}
print unique substring function
===============================
A 4
AA 2
AAG 1
AAGA 1
AAGAA 1
AG 1
AGA 1
AGAA 1
G 2
GA 2
GAA 2
GAAG 1
GAAGA 1
GAAGAA 1
=================================
A 2
AA 1
AAG 1
AAGC 1
AG 1
AGC 1
C 2
CG 1
CGA 1
CGAA 1
CGAAG 1
CGAAGC 1
G 2
GA 1
GAA 1
GAAG 1
GAAGC 1
GC 1
=================================
i want the output to be --->
same substring from file1 & file2:
=================================
A 4 2
AA 2 1
AAG 1 1
AG 1 1
G 2 2
GA 2 1
GAA 2 1
GAAG 1 1
i hope this makes my problem a liltle bit more clear. Thanks
i dont know what exactly you are doing, are you just looking for a string compare? like strcmp, or are you looking for an algorithm for searching the strings..
im not following exactly, if you havent yet do a
man strcmp
still not clear? i wonder my description... sorry
addition
problem description:
i have 2 files to read in from command line argument, content of file1 and file2 are: GAAGAA\n and CGAAGC\n respectively. what i need to do is to format these strings into substrings (i already worked out my substring part and printed out the output from above) and store them in treeA and treeB. Once that is done, i have to compare the substrings that are the same (eg, from above in my treeA and my treeB both substrings (A, AA, AAG, G, GA, GAA, GAAG) occur in 2 treeA & treeB. i want to know how to know how to do this (ie. able to find out that both same substrings occur in treeA & treeB). if i use strcmp how to i know what to compare.
typedef struct {
char *substring; /* pointer to a substring */
int freq; /* counter for the substring(s) */
}data_t;
Just to clarify ... A data structure of this kind (a "tree") is not a struct.
A struct is a name given to a chunk of contiguous memory which might consist of a number of subfields.
"A binary tree" is a thing that is physically composed of nodes and such (each of which are structs), linked by pointers. Very hairy stuff.
A binary tree is also a perfect example of what (should be) a C++ "object" or "class." With such a thing, you can create a instance of "a binary tree," and "put into it" various strings, then "see if the two trees are equal."
When you are using "a binary tree," you don't care and certainly shouldn't have to carehow it is physically implemented. A class enables you to do that. You create "this thing," and you tell this thing to "do stuff" (like put a string into itself), and you ask it "questions," like "are you equal to this tree over here?"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.