The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled Java Code
Posted by: a | March 10, 2010 @ 8:47am
Java Code
[
Download
]
public static int[] existsInSortedSubset(int[] array, int contains) { int testNo; int[] indexTree = new int[array.length +2]; int currentLvl = 0; int sumNegative = sumNegativeArray( array ); int sumPositive = sumPositiveArray( array ); array = selectionSortArray(array); System.out.println( "Start Loop"); for( int i = 0; true;i++){ testNo = 0; System.out.println("New Loop"); for( int j = 0; j < currentLvl ; j ++) { testNo += array[indexTree[j]]; } System.out.print( "Test no: " + testNo + " "); if( testNo == contains) { System.out.println( "Answer found"); int[] answer = new int[currentLvl]; for( int j = 0; j < currentLvl; j++) { answer[j] = indexTree[j]; } return answer; } System.out.print( "AnswerNotFound: "); if( testNo + sumNegative > contains || testNo + sumPositive < contains ) { System.out.print("TooHighOrLowGoingDown: "); currentLvl--; if( currentLvl == -1) { currentLvl++; indexTree[currentLvl]++; if( indexTree[currentLvl] > array.length ) { int[] answer = {-1}; return answer; } }else indexTree[currentLvl]++; //indexTree[ currentLvl]++; if( indexTree[currentLvl] > array.length) { System.out.print("test"); printArray(indexTree); while( indexTree[currentLvl] > array.length) { System.out.print("EndofArrayGoingDown: "); currentLvl--; indexTree[currentLvl]++; } } } if( testNo + sumNegative <= contains || testNo + sumPositive >= contains ) { System.out.print("ToosmallGoingUp: " ); indexTree[currentLvl + 1] = indexTree[currentLvl] +1; currentLvl++; System.out.println(currentLvl + " " +array.length); while( indexTree[currentLvl] > array.length) { System.out.print("EndofArrayGoingDown: " + indexTree[currentLvl]); currentLvl--; if( currentLvl == -1 ){ System.out.println(""); System.out.println("AnswerNotFoundTerminating"); int[] answer = {-1}; return answer; } indexTree[currentLvl]++; } } printArray(indexTree); } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.42 / 8
53 Votes
http://codebin.yi.org/540
page generated in 0.01 seconds