Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public void addValue(Integer value) {
  2. Integer returnVal = 0;
  3. Cell copy = smallest; //alias the input value to make usage easier
  4. if (smallest == null) {
  5. smallest = new Cell(value);
  6. //System.out.println("added first smallest");
  7. return;
  8. }
  9.  
  10. while((value = addToRow(copy, value)) != null){
  11. if(copy.below == null){
  12. //creat a Cell to add to below
  13. //use the aliased cell and add the new cell below
  14. //assign the new below cells top as the aliased value
  15. //return out of the loop
  16. }
  17. //to move to the next row below, reassign aliased cell to the cell below it
  18. }
  19. return;
  20. }
  21.  
  22. protected Integer addToRow(Cell curr, int value) {
  23. Cell currCell = curr; //alias the curr cell
  24. int currCellRightValue = 0;
  25. while(currCell.right != null){ //repeat until right cell is not null
  26. if( ){ // check that the value is less than the curr cell value
  27. //store the curr cell value in a temp variable
  28. //assign value to the curr cell value
  29. //return the value that was replaced
  30. }//end-if
  31. currCell = currCell.right; // reasign the curr cell to the right cell if statement was was false
  32. }//end-while
  33.  
  34. if(value < currCell.value){ // if while loop returns false on first check then replace current cell with value if it is smaller
  35. currCellRightValue = currCell.value;
  36. currCell.value = value;
  37. return currCellRightValue;
  38.  
  39. }
  40. Cell newCell= new Cell(value);
  41. currCell.right = newCell;
  42. currCell.right.left = currCell;
  43. if(currCell.above != null && currCell.above.right != null){
  44. newCell.above = currCell.above.right;
  45. newCell.above.below = currCell;
  46.  
  47. }
  48.  
  49. return null;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement