Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addValue(Integer value) {
- Integer returnVal = 0;
- Cell copy = smallest; //alias the input value to make usage easier
- if (smallest == null) {
- smallest = new Cell(value);
- //System.out.println("added first smallest");
- return;
- }
- while((value = addToRow(copy, value)) != null){
- if(copy.below == null){
- //creat a Cell to add to below
- //use the aliased cell and add the new cell below
- //assign the new below cells top as the aliased value
- //return out of the loop
- }
- //to move to the next row below, reassign aliased cell to the cell below it
- }
- return;
- }
- protected Integer addToRow(Cell curr, int value) {
- Cell currCell = curr; //alias the curr cell
- int currCellRightValue = 0;
- while(currCell.right != null){ //repeat until right cell is not null
- if( ){ // check that the value is less than the curr cell value
- //store the curr cell value in a temp variable
- //assign value to the curr cell value
- //return the value that was replaced
- }//end-if
- currCell = currCell.right; // reasign the curr cell to the right cell if statement was was false
- }//end-while
- if(value < currCell.value){ // if while loop returns false on first check then replace current cell with value if it is smaller
- currCellRightValue = currCell.value;
- currCell.value = value;
- return currCellRightValue;
- }
- Cell newCell= new Cell(value);
- currCell.right = newCell;
- currCell.right.left = currCell;
- if(currCell.above != null && currCell.above.right != null){
- newCell.above = currCell.above.right;
- newCell.above.below = currCell;
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement