Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit132060f

Browse files
authored
Merge branch 'Development' into Development
2 parents4fd7698 +04f6924 commit132060f

27 files changed

+633
-513
lines changed

‎src/main/java/com/conversions/AnyBaseToDecimal.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
publicclassAnyBaseToDecimal {
44
/**
55
* This method produces a decimal value of any given input number of any base
6+
*
67
* @param inpNum String of which we need the decimal value and base in integer format
78
* @return string format of the decimal value
89
*/
@@ -12,28 +13,28 @@ public String convertToDecimal(String inpNum, int base) {
1213
intnum =0;
1314
intpow =1;
1415

15-
for (inti=len-1;i>=0;i--) {
16+
for (inti =len -1;i >=0;i--) {
1617
if (valOfChar(inpNum.charAt(i)) >=base) {
1718
return"Invalid Number";
1819
}
19-
num +=valOfChar(inpNum.charAt(i))*pow;
20+
num +=valOfChar(inpNum.charAt(i)) *pow;
2021
pow *=base;
2122
}
2223
returnString.valueOf(num);
2324
}
2425

2526
/**
2627
* This method produces integer value of the input character and returns it
28+
*
2729
* @param c Char of which we need the integer value of
2830
* @return integer value of input char
2931
*/
3032

3133
privatestaticintvalOfChar(charc) {
3234
if (c >='0' &&c <='9') {
33-
return (int)c -'0';
34-
}
35-
else {
36-
return (int)c -'A' +10;
35+
return (int)c -'0';
36+
}else {
37+
return (int)c -'A' +10;
3738
}
3839
}
3940
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagesrc.main.java.com.conversions;
2+
3+
/**
4+
* Convert the binary number into gray code
5+
*/
6+
publicclassBinaryToGray {
7+
8+
/**
9+
* convert the binary number into gray code
10+
*
11+
* @param binaryCode binary number
12+
* @return grayCode return as string
13+
*/
14+
publicStringbinaryToGray(StringbinaryCode) {
15+
StringBuildergrayCode =newStringBuilder(Character.toString(binaryCode.charAt(0)));
16+
17+
for (inti =0;i <binaryCode.length() -1;i++) {
18+
if (binaryCode.charAt(i) ==binaryCode.charAt(i +1))
19+
grayCode.append("0");
20+
else
21+
grayCode.append("1");
22+
}
23+
returngrayCode.toString();
24+
}
25+
26+
}

‎src/main/java/com/conversions/BinaryToHexadecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class BinaryToHexadecimal {
1111
* hm to store hexadecimal codes for binary numbers
1212
* within the range: 0000 to 1111 i.e. for decimal numbers 0 to 15
1313
*/
14-
privatestaticMap<Integer,String>hmHexadecimal =newHashMap<>(16);
14+
privatestaticMap<Integer,String>hmHexadecimal =newHashMap<>(16);
1515

1616
static {
1717
inti;

‎src/main/java/com/conversions/DecimalToAnyBase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
importjava.util.ArrayList;
44

55
publicclassDecimalToAnyBase {
6+
67
/**
78
* This method produces a String value of any given input decimal in any base
8-
* @param inp Decimal of which we need the value in base in String format
9+
*
10+
* @param inp Decimal of which we need the value in base in String format
911
* @param base base in which we want the decimal value to be converted into
1012
* @return string format of the converted value in the given base
1113
*/
12-
1314
publicStringconvertToAnyBase(intinp,intbase) {
1415
ArrayList<Character>charArr =newArrayList<>();
1516

1617
while (inp >0) {
17-
charArr.add(reVal(inp%base));
18+
charArr.add(reVal(inp %base));
1819
inp /=base;
1920
}
2021

2122
StringBuilderstr =newStringBuilder(charArr.size());
22-
for(Characterch:charArr) {
23+
for(Characterch:charArr) {
2324
str.append(ch);
2425
}
2526

@@ -28,14 +29,15 @@ public String convertToAnyBase(int inp, int base) {
2829

2930
/**
3031
* This method produces character value of the input integer and returns it
32+
*
3133
* @param num integer of which we need the character value of
3234
* @return character value of input integer
3335
*/
3436

3537
privatecharreVal(intnum) {
3638
if (num >=0 &&num <=9)
37-
return (char)(num +'0');
39+
return (char)(num +'0');
3840
else
39-
return (char)(num -10 +'A');
41+
return (char)(num -10 +'A');
4042
}
4143
}

‎src/main/java/com/conversions/DecimalToHexadecimal.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
importjava.math.BigInteger;
44

55
publicclassDecimalToHexadecimal {
6-
privatestaticfinalcharhexChars[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
6+
privatestaticfinalchar[]hexChars= {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
77
privatestaticfinalBigIntegervalueHex =newBigInteger("16");
88

99
/**
1010
* This method converts and decimal number to a Hexadecimal number
11+
*
1112
* @param decimalStr
1213
* @return hexadecimal number
1314
*/
14-
publicStringdecimalToHex(StringdecimalStr){
15+
publicStringdecimalToHex(StringdecimalStr){
1516
BigIntegerdecimal =newBigInteger(decimalStr);
1617

1718
intrem;

‎src/main/java/com/conversions/DecimalToOctal.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
importjava.math.BigInteger;
44

55
publicclassDecimalToOctal {
6-
privatestaticfinalcharoctalChars[] = {'0','1','2','3','4','5','6','7'};
6+
privatestaticfinalchar[]octalChars= {'0','1','2','3','4','5','6','7'};
77
privatestaticfinalBigIntegervalueOctal =newBigInteger("8");
88

99
/**
1010
* This method converts and decimal number to a octal number
11+
*
1112
* @param decimalStr
1213
* @return octal number
1314
*/
14-
publicStringdecimalToOctal(StringdecimalStr){
15+
publicStringdecimalToOctal(StringdecimalStr){
1516
BigIntegerdecimal =newBigInteger(decimalStr);
1617

1718
intrem;
1819
Stringoctal ="";
19-
while(decimal.compareTo(BigInteger.ZERO) >0) {
20+
while(decimal.compareTo(BigInteger.ZERO) >0) {
2021
rem =decimal.mod(valueOctal).intValueExact();
2122
octal =octalChars[rem] +octal;
2223
decimal =decimal.divide(valueOctal);

‎src/main/java/com/dataStructures/BinaryTree.java

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,42 @@
22

33
/**
44
* Binary tree for general value type, without redundancy
5-
* @author RICARDO
5+
*
66
* @param <T> root data
77
*/
8+
89
publicclassBinaryTree<TextendsComparable> {
910
privatefinalTdata;
10-
privateBinaryTreeright,// the upper binary tree
11-
left;// the lower binary tree
11+
privateBinaryTreeright,// the upper binary tree
12+
left;// the lower binary tree
1213

1314
publicBinaryTree(Tdata) {
1415
this.data =data;
1516
}
1617

1718
@Override
18-
publicStringtoString(){
19+
publicStringtoString(){
1920
returnthis.data.toString();
2021
}
21-
22+
2223
/**
2324
* inserts a new value in it's correspondant place
24-
* @param newDataValue value of the new banary tree to add on this tree
25+
*
26+
* @param newDataValue value of the new binary tree to add on this tree
2527
*/
26-
publicvoidinsert(TnewDataValue){
28+
publicvoidinsert(TnewDataValue){
2729
this.insert(newBinaryTree(newDataValue));
2830
}
29-
31+
3032
/**
3133
* inserts a new binary tree in it's correspondant place
32-
* @param newData new value to add on this tree
34+
*
35+
* @param newData new value to add on this tree
3336
*/
34-
publicvoidinsert(BinaryTreenewData){
35-
37+
publicvoidinsert(BinaryTreenewData){
38+
3639
intcpr =newData.data.compareTo(this.data);//new value comparission respect to actual value
37-
40+
3841
if (cpr <0)
3942
if (this.left ==null)
4043
this.setLeft(newData);
@@ -51,12 +54,13 @@ else if (cpr > 0)
5154

5255
/**
5356
* search and specific value on the tree
54-
* @param data Searched value
55-
* @return Binary tree wich contains the value, null if it doesn't exist
57+
*
58+
* @param data Searched value
59+
* @return Binary tree which contains the value, null if it doesn't exist
5660
*/
57-
publicBinaryTreesearch(Tdata){
61+
publicBinaryTreesearch(Tdata){
5862
intcpr =data.compareTo(this.data);//new value comparission respect to actual value
59-
63+
6064
if (cpr <0) {
6165
if (this.left ==null)
6266
returnnull;//the value doesn't exist
@@ -65,43 +69,45 @@ public BinaryTree search(T data){
6569
if (cpr >0) {
6670
if (this.right ==null)
6771
returnnull;//the value doesn't exist
68-
returnthis.right.search(data);
72+
returnthis.right.search(data);
6973
}
7074
returnthis;
7175
}
72-
76+
7377
/**
7478
* Checks if the data value exist in the tree
79+
*
7580
* @param data data to be searched
7681
* @return true if this tree contains the data value, false if not.
7782
*/
78-
publicbooleancontains(Tdata){
83+
publicbooleancontains(Tdata){
7984
returnthis.search(data) !=null;
8085
}
81-
86+
8287
/**
8388
* uses recursive black magic to print this tree in console
89+
*
8490
* @param tabCounter prev tabs
8591
*/
86-
privatevoidprint(inttabCounter){
92+
privatevoidprint(inttabCounter){
8793
for (inti =0;i <tabCounter;i++)
8894
System.out.print("\t");
89-
95+
9096
System.out.println(this);
91-
97+
9298
if (this.left !=null)
9399
this.left.print(tabCounter +1);//it can't be ++ , pls don't change it
94100
if (this.right !=null)
95101
this.right.print(tabCounter +1);//it can't be ++ , pls don't change it
96102
}
97-
103+
98104
/**
99105
* uses black magic to print this tree in console
100106
*/
101-
publicvoidprint(){
107+
publicvoidprint(){
102108
this.print(0);
103109
}
104-
110+
105111
//getters and setters
106112
publicTgetData() {
107113
returndata;

‎src/main/java/com/dataStructures/DisjointSet.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* <p>
1616
* 2. quickly query two elements whether contained in the same set, requiring about O(1) time.
1717
*
18-
* @author yangxf
1918
*/
2019
publicclassDisjointSet<T>implementsSerializable {
2120
privatestaticfinallongserialVersionUID =3134700471905625636L;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp