LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 12-07-2010, 02:31 PM   #1
sorinclaudiu
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Rep: Reputation: 2
how to make a binary tree from an external file ??


My assessment is making a tree from a text file as follows: -reading a file line by line
-making a binary tree from it
- traverse by level the binary tree
- posting the traversal result to the same file without overwriting the text file- it is required to be append to the bottom of the text file
(i have to do this in 4 languages: c#,PHP from Xampp,java, python)
-----------------------------
i read the file with this script in java:


public class FileToStringArray {

private String strLine;
private String[] stringArray;
private FileInputStream in;
private BufferedReader br;
private int sizeOfArray = 0;
private File file = null;
private FileReader fr = null;
private LineNumberReader lnr = null;
private String fileName;

public FileToStringArray(String fileName){
this.fileName = fileName;
countLines();

}

private void countLines(){ //cound the lines and puts the number into sizeOfArray
try{

file = new File(fileName);
fr = new FileReader(file);
lnr = new LineNumberReader(fr);
String line = "";
while ((line = lnr.readLine()) != null){
sizeOfArray++;
}
}catch(Exception e){
System.out.println("Bad File");
System.out.println(e);
}
sizeOfArray--;
}//end of countLines

public String[] getString(){ //makes and array of size sizeOfArray and fills it with text
try{

in = new FileInputStream(fileName);
br = new BufferedReader(new InputStreamReader(in));

stringArray = new String[sizeOfArray];

for (int j = 0; j < stringArray.length; j++){
stringArray[j] = br.readLine();


}in.close();
}
catch(Exception e){
System.out.println("Bad File");
System.out.println(e);
}

return stringArray;
}//end of get string
public static void main(String arg[]){

String x[] = new FileToStringArray("file.txt").getString();

for(int i = 1; i<x.length;i++){
System.out.println(x[i]);
}
}//end of main
}//end of class
---------------
but how i can make a binary tree from this point???

please help!!!!!!!!!
 
Old 12-07-2010, 02:53 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Are you sure you should be asking for help on an assessment?

Last edited by dugan; 12-07-2010 at 03:16 PM.
 
1 members found this post helpful.
Old 12-08-2010, 09:25 AM   #3
sorinclaudiu
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 2
this is only to pacify you

that's your option! i don't condemn anyone who don't have any interest to help !!! i wish you all the best!
maybe i've made a mistake from my side!!! sorry......
 
0 members found this post helpful.
Old 12-08-2010, 10:05 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
If I were the organization conducting the assessment, I would search on the Internet for elements from each person's code (the code you've shown us, for example) to see whether anyone was getting outside help, which would imply cheating. For the sake of your own continuing moral maturation (a journey none of us ever finish), I hope they catch you.

I've quoted your code, so you can't edit it away. Your only guarantee against being caught is to completely rewrite your code.

Go and sin no more.
Quote:
Originally Posted by sorinclaudiu View Post
My assessment is making a tree from a text file as follows: -reading a file line by line
-making a binary tree from it
- traverse by level the binary tree
- posting the traversal result to the same file without overwriting the text file- it is required to be append to the bottom of the text file
(i have to do this in 4 languages: c#,PHP from Xampp,java, python)
-----------------------------
i read the file with this script in java:


public class FileToStringArray {

private String strLine;
private String[] stringArray;
private FileInputStream in;
private BufferedReader br;
private int sizeOfArray = 0;
private File file = null;
private FileReader fr = null;
private LineNumberReader lnr = null;
private String fileName;

public FileToStringArray(String fileName){
this.fileName = fileName;
countLines();

}

private void countLines(){ //cound the lines and puts the number into sizeOfArray
try{

file = new File(fileName);
fr = new FileReader(file);
lnr = new LineNumberReader(fr);
String line = "";
while ((line = lnr.readLine()) != null){
sizeOfArray++;
}
}catch(Exception e){
System.out.println("Bad File");
System.out.println(e);
}
sizeOfArray--;
}//end of countLines

public String[] getString(){ //makes and array of size sizeOfArray and fills it with text
try{

in = new FileInputStream(fileName);
br = new BufferedReader(new InputStreamReader(in));

stringArray = new String[sizeOfArray];

for (int j = 0; j < stringArray.length; j++){
stringArray[j] = br.readLine();


}in.close();
}
catch(Exception e){
System.out.println("Bad File");
System.out.println(e);
}

return stringArray;
}//end of get string
public static void main(String arg[]){

String x[] = new FileToStringArray("file.txt").getString();

for(int i = 1; i<x.length;i++){
System.out.println(x[i]);
}
}//end of main
}//end of class
---------------
but how i can make a binary tree from this point???

please help!!!!!!!!!
 
Old 12-09-2010, 09:30 AM   #5
sorinclaudiu
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by wje_lq View Post
If I were the organization conducting the assessment, I would search on the Internet for elements from each person's code (the code you've shown us, for example) to see whether anyone was getting outside help, which would imply cheating. For the sake of your own continuing moral maturation (a journey none of us ever finish), I hope they catch you.

I've quoted your code, so you can't edit it away. Your only guarantee against being caught is to completely rewrite your code.

Go and sin no more.
I don't know what are you talking about!!!! i am not a thiever and you are totally wrong from all points of view!!!!
maybe you have another problem which doesn't have any related link with my task!!! I haven't applied for any kind of job as you are sustaining!!! you are totally wrong !! nobody will asses my knowledge !!!!!i am not a developer and i am not gaining my life from that ...i have attended high level studies ... i am a wide minded person...
don't talk about what you really don,t know...you really overcome and overestimated you.
 
Old 12-09-2010, 12:41 PM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by sorinclaudiu View Post
i am not a thiever
If that is really true, then you have nothing to fear.

Best wishes.
 
Old 12-09-2010, 01:07 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by sorinclaudiu View Post
I don't know what are you talking about!!!! i am not a thiever and you are totally wrong from all points of view!!!!
maybe you have another problem which doesn't have any related link with my task!!! I haven't applied for any kind of job as you are sustaining!!! you are totally wrong !! nobody will asses my knowledge !!!!!i am not a developer and i am not gaining my life from that ...i have attended high level studies ... i am a wide minded person...
don't talk about what you really don,t know...you really overcome and overestimated you.
I can see that English is not your first language. Perhaps you chose the wrong word when you said "assessment." What did you actually mean?

Usually, a programming assessment is a test given by a potential employer to test the skill levels of candidates.
 
Old 12-09-2010, 04:07 PM   #8
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by dugan View Post
Usually, a programming assessment is a test given by a potential employer to test the skill levels of candidates.
I thought that was what it was, too. Particulary because:
Quote:
Originally Posted by sorinclaudiu View Post
i have to do this in 4 languages:
 
Old 12-10-2010, 01:56 PM   #9
sorinclaudiu
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 2
you really don't understand anything!! i had to asses my knowledge!!!! you are too narrow minded!!
i will not complicate anymore with this forum !!
also it demonstrated me that is very useless!!
this forum is totally useless!!!!!!!!!!!!!!!!!!!!!!!!!!!1
 
Old 12-10-2010, 02:01 PM   #10
sorinclaudiu
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 2
I will delete my account definitely......................
 
1 members found this post helpful.
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make with make file yields error: /usr/bin/javac: cannot execute binary file bweaver Ubuntu 4 11-19-2010 02:58 PM
vmlinuz file format problems - redhat kernel source tree & make tsnider Linux - Kernel 1 04-05-2008 09:45 AM
vmlinuz file format problems - redhat kernel source tree & make tsnider Red Hat 1 03-25-2008 11:26 AM
make link to binary file mfran2002 Linux - Newbie 3 07-24-2007 02:24 PM
Lost File tree on my external hard drive!!!?? X_user Linux - Hardware 1 09-17-2006 11:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration