Advertisement
benjaminliu

Untitled

Feb 28th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /* implement ALL the methods in this class.
  2. *
  3. *
  4. * This project is based on Chapter 3, section 5, Matrices of Relations
  5. *
  6. * Good luck
  7. */
  8.  
  9. import java.util.*;
  10. import java.lang.Math;
  11. /**
  12. *
  13. * @author
  14. * @version (a version number or a date)
  15. */
  16. /*
  17. * For this project, you may assume all int[][] have square dimensions
  18. *
  19. * Remember to not change the parameter!!!!!!!!!
  20. */
  21. public class FunctionsChapter3StylePart3
  22. {
  23. /*
  24. * add the fewest 1s to copy of matrix m so that the copy is reflexive
  25. *
  26. * Remember to not change the parameter!!!!!!!!!
  27. */
  28. public static int[][] makeReflexive(int[][] m)
  29. {
  30. int[][] ans = new int[m.length][];
  31. // for(int i = 0; i < m.length; i++)
  32. // ans[i] = m[i].clone();
  33.  
  34. for(int i = 0; i < m.length; i++)
  35. for(int j = 0; j < m.length; j++){
  36. ans[i][j] = m[i][j];
  37. }
  38.  
  39. for(int i = 0; i < m.length; i++){
  40. ans[i][i] = 1;
  41. }
  42. return ans;
  43. }
  44.  
  45. /*
  46. * add the fewest 1s to copy of matrix m so that the copy is symmetric
  47. *
  48. * Remember to not change the parameter!!!!!!!!!
  49. */
  50. public static int[][] makeSymmetric(int[][] m)
  51. {
  52. int[][] ans = new int[m.length][];
  53. for(int i = 0; i < m.length; i++)
  54. for(int j = 0; j < m.length; j++){
  55. ans[i][j] = m[i][j];
  56. }
  57.  
  58. for(int i = 0; i < m.length; i++)
  59. for(int j = 0; j < m.length; j++){
  60. if(ans[i][j] == 1) ans[j][i] = 1;
  61. }
  62. return ans;
  63. }
  64.  
  65. /*
  66. * add the fewest 1s to copy of matrix m so that the copy is transitive
  67. *
  68. * Remember to not change the parameter!!!!!!!!!
  69. */
  70. public static int[][] makeTransitive(int[][] m)
  71. {
  72.  
  73. int[][] ans = new int[m.length][];
  74. for(int i = 0; i < m.length; i++)
  75. for(int j = 0; j < m.length; j++){
  76. ans[i][j] = m[i][j];
  77. }
  78.  
  79.  
  80. return ans;
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement