-
-
Notifications
You must be signed in to change notification settings - Fork 359
Added the java version of the bubble algorithm #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the java version of the bubble algorithm #131
Conversation
Can you add an example like this. |
In Java we must have all of the code inside a class like this example :
Should I add the class structure or just the functions inside it ? |
Just wrap a class around |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome @xam4lor! Thanks for your code contribution. Java didn't get much love in the AAA yet, so I'm happy to see someone add a few algorithms for it.
I see, you and @Gathros have already improved a few things about your PR. I, too, have some things that I'd like you to change. Most of them are more of a style-guide kind of deal.
First off, I noticed that you used tabs in your code. There is nothing inherently bad about that, don't get me wrong, but all the other Java code in the Algorithm Archive already uses 4 spaces instead and we like to keep things consistent. There are also some places in both .java files where you use tabs and spaces. You should clean that up.
|
||
System.out.println("\n\nSorted array :"); | ||
for (int i = 0; i < test.length; i++) { | ||
System.out.print(test[i] + " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use System.out.print()
here, which is fine to print the list, but you should add an empty System.out.println()
or System.out.print("\n")
at the end so that there's a line break in the end. Otherwise the output looks like this (at least on Linux):
marius@DasPC:java> java Bubble
Unsorted array :
20 -3 50 1 -6 59
Sorted array :
-6 -3 1 20 50 59 marius@DasPC:java>
See how the prompt marius@DasPC:java>
is on the same line as the last line of output?
@@ -0,0 +1,47 @@ | |||
public class Bogo { | |||
// The shuffle() function can be found in code/java/bogo.java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already in code/java/bogo.java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was for the website implementation ! The user don't see the shuffle() methode !
@xam4lor Hold on there for a second! I recommend not adding more and more stuff to this pull request. The more algorithms you add, the more clustered the conversation will be and the harder it will be to review the pull request. Bubble Sort and Bogo Sort in one PR is fine, but I recommend creating separate PRs for separate algorithms. Otherwise it will take ages to get this merged. Alternatively, you can add a few algorithms and we'll wait until you're done with all of them. Then we can review all of them at once. In that case, just add stuff and when you're done with everything, mention me with @Butt4cak3 and I'll get back to you. Your call. |
@xam4lor Do you mind to move the C# commit into a separate PR? |
Oh... I thought the newest commit was also Java, but it's actually C#. Yeah, you should definitely not add multiple algorithms in different languages to one pull request. If you have any questions on how to split things up properly, ask me here, or even better, hop over to our Discord (linked in the README of this repo) and ask there. |
Okay okay 🤣 |
@xam4lor do you mind joining https://discord.gg/2kWgSWB ? |
Added an empty println() at the end and put spaces instead of tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. Now that we have the technical stuff figured out, I made a proper review for the code. I can't find anything inherently wrong with it.
I noticed that you basically just ported my JavaScript code to Java, but that's perfectly fine. That's actually pretty good, because now the implementations in different languages are more like each other, just tweaked for the respective language.
Once you fix the three things I commented, this one is ready to merge.
for (int i = 0; i < test.length; i++) { | ||
System.out.print(test[i] + " "); | ||
} | ||
System.out.println("\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need both println
and "\n"
. println
already automatically adds a "\n"
at the end of the string. Using System.out.println("\n")
will actually print two line breaks.
Go for either System.out.print("\n")
or System.out.println()
. I prefer the latter, but it's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know if it's better with one or two spaces ...
@@ -0,0 +1,31 @@ | |||
public class Bubble { | |||
static void bubbleSort(int[] arr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire file is still indented with tabs. Again, not inherently bad, but you should replace these with 4 spaces each for consistency.
System.out.println("\n\nSorted array :"); | ||
for (int i = 0; i < test.length; i++) { | ||
System.out.print(test[i] + " "); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty System.out.println()
here to fix the output, just as in bogo.java.
So I think it's better if all of the codes are the same in the way of thinking, because the user can compare different languages ! |
Everything is looking good now. Let's merge and then realize what a massive mistake we have done! \o/ |
No description provided.