yassmin

Untitled

Apr 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.util.LinkedList;
  2.  
  3. public class step1 {
  4. static LinkedList<node> array[];
  5. static LinkedList<node> remain;
  6. static int nOfBits = 0;
  7.  
  8. static String Binary(int decimal) {
  9. array = new LinkedList[nOfBits + 1];
  10. StringBuilder conc = new StringBuilder();
  11. String bin = Integer.toBinaryString(decimal);
  12. int count = 0;
  13. for (int i = 0; i < bin.length(); i++) {
  14. if (bin.charAt(i) == '1') {
  15. count++;
  16. }
  17. }
  18. for (int i = 0; i < nOfBits - bin.length(); i++) {
  19. conc.append("0");
  20. }
  21. conc.append(bin);
  22. node new_node = new node(2 ^ nOfBits - 1);
  23. new_node.minterm = conc.toString();
  24. new_node.min[decimal] = true;
  25. new_node.symbol.append(Integer.toString(decimal)).append(',');
  26. array[count].add(new_node);
  27. return conc.toString();
  28. }
  29.  
  30. public void solve(LinkedList<node> tmp[]) {
  31. LinkedList<node> tmpnext[] = new LinkedList[tmp.length + 1];
  32. int i = 0;
  33. while (i < tmp.length - 1) {
  34. for (int j = 0; j < tmp[i].size(); j++) {
  35. for (int k = 0; k < tmp[i + 1].size(); k++) {
  36. int count = 0;
  37. StringBuilder newminterm = new StringBuilder();
  38. for (int l = 0; l < nOfBits; l++) {
  39.  
  40. if (tmp[i].get(j).minterm.charAt(l) == tmp[i].get(k).minterm.charAt(l)) {
  41. newminterm.append(tmp[i].get(j).minterm.charAt(l));
  42. continue;
  43.  
  44. } else {
  45. count++;
  46. newminterm.append('-');
  47. if (count > 0)
  48. break;
  49.  
  50. }
  51. }
  52. if (count == 1) {
  53. node new_node = new node(nOfBits);
  54. new_node.minterm = newminterm.toString();
  55. tmpnext[i].add(new_node);
  56. }
  57. }
  58. }
  59. }
  60.  
  61. }
  62.  
  63. public static void main(String[] args) {
  64. // System.out.println(Binary(1, 4));
  65.  
  66. String input = "1,2,3,4";
  67. String[] spliter = input.split(",");
  68. nOfBits = 3;
  69. for (int i = 0; i < spliter.length; i++) {
  70. int in = Integer.parseInt(spliter[i]);
  71. String biny = Binary(in);
  72. spliter[i]=biny;
  73.  
  74. }
  75. LinkedList<node>[] myList = new LinkedList<node>[spliter.length];
  76. //String str =
  77.  
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment