Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* implement ALL the methods in this class.
- *
- *
- * This project is based on Chapter 3, section 5, Matrices of Relations
- *
- * Good luck
- */
- import java.util.*;
- import java.lang.Math;
- /**
- *
- * @author
- * @version (a version number or a date)
- */
- /*
- * For this project, you may assume all int[][] have square dimensions
- *
- * Remember to not change the parameter!!!!!!!!!
- */
- public class FunctionsChapter3StylePart3
- {
- /*
- * add the fewest 1s to copy of matrix m so that the copy is reflexive
- *
- * Remember to not change the parameter!!!!!!!!!
- */
- public static int[][] makeReflexive(int[][] m)
- {
- int[][] ans = new int[m.length][];
- // for(int i = 0; i < m.length; i++)
- // ans[i] = m[i].clone();
- for(int i = 0; i < m.length; i++)
- for(int j = 0; j < m.length; j++){
- ans[i][j] = m[i][j];
- }
- for(int i = 0; i < m.length; i++){
- ans[i][i] = 1;
- }
- return ans;
- }
- /*
- * add the fewest 1s to copy of matrix m so that the copy is symmetric
- *
- * Remember to not change the parameter!!!!!!!!!
- */
- public static int[][] makeSymmetric(int[][] m)
- {
- int[][] ans = new int[m.length][];
- for(int i = 0; i < m.length; i++)
- for(int j = 0; j < m.length; j++){
- ans[i][j] = m[i][j];
- }
- for(int i = 0; i < m.length; i++)
- for(int j = 0; j < m.length; j++){
- if(ans[i][j] == 1) ans[j][i] = 1;
- }
- return ans;
- }
- /*
- * add the fewest 1s to copy of matrix m so that the copy is transitive
- *
- * Remember to not change the parameter!!!!!!!!!
- */
- public static int[][] makeTransitive(int[][] m)
- {
- int[][] ans = new int[m.length][];
- for(int i = 0; i < m.length; i++)
- for(int j = 0; j < m.length; j++){
- ans[i][j] = m[i][j];
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement