Skip to content

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

Merged
merged 11 commits into from
Jun 28, 2018
Merged

Added the java version of the bubble algorithm #131

merged 11 commits into from
Jun 28, 2018

Conversation

xam4lor
Copy link
Contributor

@xam4lor xam4lor commented Jun 27, 2018

No description provided.

@Gathros Gathros added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jun 27, 2018
@Gathros
Copy link
Contributor

Gathros commented Jun 27, 2018

Can you add an example like this.

@xam4lor
Copy link
Contributor Author

xam4lor commented Jun 27, 2018

In Java we must have all of the code inside a class like this example :

package test;

public class Main {
	public static void main(String[] args) {
             // blabla
        }
}

Should I add the class structure or just the functions inside it ?
(Sorry for my bad English, I'm French ;) )

@Gathros
Copy link
Contributor

Gathros commented Jun 27, 2018

Just wrap a class around main and BubbleSort so it's executable.

Copy link
Contributor

@Butt4cak3 Butt4cak3 left a 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] + " ");
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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 !

@Butt4cak3
Copy link
Contributor

@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.

@june128
Copy link
Member

june128 commented Jun 27, 2018

@xam4lor Do you mind to move the C# commit into a separate PR?

@Butt4cak3
Copy link
Contributor

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.

@xam4lor
Copy link
Contributor Author

xam4lor commented Jun 27, 2018

Okay okay 🤣
I'm really new with opensource projects !!
Can somebody clean and split all of the requests and things and make the good changes please ??

@june128
Copy link
Member

june128 commented Jun 27, 2018

@xam4lor do you mind joining https://discord.gg/2kWgSWB ?
I don't know, if we can actually split things up or if you need to do so. (@Butt4cak3 ?)

Added an empty println() at the end and put spaces instead of tabs.
Copy link
Contributor

@Butt4cak3 Butt4cak3 left a 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");
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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] + " ");
}
Copy link
Contributor

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.

@xam4lor
Copy link
Contributor Author

xam4lor commented Jun 28, 2018

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 !

@Butt4cak3 Butt4cak3 self-assigned this Jun 28, 2018
@Butt4cak3
Copy link
Contributor

Everything is looking good now. Let's merge and then realize what a massive mistake we have done! \o/

@Butt4cak3 Butt4cak3 merged commit 64a9d0f into algorithm-archivists:master Jun 28, 2018
@xam4lor xam4lor deleted the java-language-implementation branch June 29, 2018 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants