Your browser does not support our blog javascript

programming java

search for more blogs here

 
Home - Take this blog! - Get your Author's Pass Here - Submit Comments Below

Java Programming (Trees) - Help Please

Posted by ~Ray @ 2008-11-13 12:38:14


***************************************************************************************Edit:To expand on this the output when trying to print out the tree's are null it is a empty []. This should contain the bit string in an ArrayList.*************************************************************************************** Hello. I am in a class where we have to create a Java programming implementing a tree. We are supposed to take two numbers (but right now I can't even get one to work) and convert it to a bit string (e g. 4: would be 00000100) but I am having some difficulty. I wrote this so far and was guided by the instructor to implement the tree in this manner. He also gave us another program that he said we could use to convert the number but it converts it to a string. Anyway. I am a little lost and I believe I am missing some parts in the "private final static ArrayList generateTree( BigInteger[] vs int n int k )" in the last for loop before the Ts add(T) part. Please if anyone could help me out in leading me in the right direction. I would greatly appreciate it. (I added some println statements throughout the program that I was using to help me out but I am still stuck.)import java math.*;import java util.*;import java io.*;import java lang.*;public class Tree { private int id; private BigInteger val; private Tree left; private Tree right; public Tree ( int id. String s ) { this id = id; this val = new BigInteger(s); } public Tree( int id. BigInteger val ) { this id = id; this val = val; } public Tree( Tree left. Tree right ) { this id = 0; this val = null; this left = left; this right = right; } public Tree( int id. String s. Tree left. Tree right ) { this( id s ); this left = left; this right = right; } public static ArrayList generateTree( int n ) { return generateTree( new BigInteger[n] ); } public static ArrayList generateTree( BigInteger[] vs ) { /*vs[0]=zero; vs[1]=one; vs[2]=two; vs[3]=three;*/ return generateTree( vs vs length. 0 ); } private final static ArrayList generateTree( BigInteger[] vs int n int k ) { ArrayList<Tree> Ts = new ArrayList<Tree>(); System out println("vs[k] = "+vs[k]);System out println("n = "+n);System out println("k = "+k); if( n == 1 ) { Ts add( new Tree( k vs[k] ) ); } else { for( int i=1; i < n-1; i++ ) { ArrayList Ls = generateTree( vs i k ); ArrayList Rs = generateTree( vs i+1 k+1 ); System out println("hello"); for( int l=0; l < Ls size(); l++ ) { for( int r=0; r < Rs size(); r++ ) { Tree T = new Tree((Tree)Ls get(l). (Tree)Rs get(l)); Ts add(T); } } } } return Ts; } public static final BigInteger zero=BigInteger valueOf(0); public static final BigInteger one=BigInteger valueOf(1); public static BigInteger bigones(int nbits) { return one shiftLeft(nbits) subtract(one); } public static BigInteger bignot(int nbits,BigInteger B) { return bigones(nbits) andNot(B); } public static String big2string(BigInteger BI,int bits) { String s = BI toString(2); StringBuffer b = new StringBuffer(bits); int n = bits-s length(); while(--n >= 0) { b append('0'); } b append(s); return b toString(); } public static final BigInteger nand(int nbits,BigInteger X,BigInteger Y) { X=X and(Y); return bignot(nbits,X); } public static void main(String[] args) { InputStreamReader isr = new InputStreamReader( System in ); BufferedReader stdin = new BufferedReader( isr ); String inputOne = ""; String inputTwo = ""; try { System out print( "Type some data for the program: " ); inputOne = stdin readLine(); System out print( "Type some data for the program: " ); inputTwo = stdin readLine(); } catch (IOException e) { e printStackTrace(); } BigInteger A = new BigInteger(inputOne); BigInteger B = new BigInteger(inputTwo); //BigInteger C = nand(8,A,B); String AString = big2string(A,8); String BString = big2string(B,8); //String CString = big2string(C,8); int input1 = Integer parseInt(inputOne); int input2 = Integer parseInt(inputTwo); System out println("A="+AString); System out println("B="+BString); //System out println("C="+CString); Tree T1 = new Tree(input1,8); //Tree T2 = new Tree(input2,8); ArrayList newT1 = T1 generateTree(input1); //ArrayList newT2 = T2 generateTree(input2); //T1 generateTree(input1); //T2 generateTree(input2); //ArrayList newT1 = generateTree(8); //ArrayList newT2 = generateTree(input2); //for(int m = 0; m < T1 size //Tree T = new Tree((Tree)Ls get(l). (Tree)Rs get(l)); System out print("newT1 = ");System out println(newT1); //System out print("newT2 = ");System out println(newT2); //System out print("input1 = ");System out println(T1 toString()); //System out println("input2 = "+T2 toString()); //System out println("input1 = "+T1 generateTree(input1)); //System out println("input2 = "+T2 generateTree(input2)); //System out println("input1 = "+generateTree(input1)); //System out println("input2 = "+generateTree(input2)); }}Edited by: laughdat08 on Nov 14. 2007 5:39 PMEdited by: laughdat08 on Nov 14. 2007 5:41 PMEdited by: laughdat08 on Nov 14. 2007 5:43 PM[ADVERTHERE]Related article:
http://forum.java.sun.com/thread.jspa?threadID=5236679


0 Comments:


No comments have been posted yet!

From:   Website:
Subject:   Code:
Message:


   

 


 

 

 





blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




blogs home