Skip to content
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

[Algo] Adding Heap sort [Java] #509

Closed
wants to merge 2 commits into from

Conversation

pentalpha
Copy link

Adds heap_sort.java, which includes an Java implementation of the Heap sort algorithm, using a custom Heap data structure.

About Heap sort: Heap sort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum. (Wikipedia)

Closes #508

By submitting this pull request I confirm I've read and complied with the
below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the commit guidelines for this project.
  • My code follows the standard code structure.
  • This pull request has a descriptive title. For example, {Tag}: Add {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
  • This pull request shall only be reviewed and merged once all the checks passes. No maintainer or supporter shall be obliged to review it before this condition is met.
  • I have mentioned the issue number correctly (with hyperlink) in this pull request description.

After you submit your pull request, DO NOT click the 'Update Branch' button.

This commit adds heap_sort.java, which includes an Java
implementation of the Heap sort algorithm, using a custom
Heap data structure.

Closes NITSkmOS#508
heap.removeMin();
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -10,7 +10,7 @@
             heap.removeMin();
         }
     }
-    
+
     public static void main(String[] args) {
         int[] arr = new int[] {2, 3, 0, 4, -1, 34, 10, 12, 6, -10};
         run_heap_sort(arr);

System.out.println(element);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -18,7 +18,7 @@
             System.out.println(element);
         }
     }
-    
+
     private static class HeapMin {
         private int actualSize, maxSize;
         private int[] nodes;

return 0;
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -85,7 +85,7 @@
                 return 0;
             }
         }
-        
+
         /**
          * Rises a heap element
          * @param i Element index

int aux = nodes[parent(i)];
nodes[parent(i)] = nodes[i];
nodes[i] = aux;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -98,7 +98,7 @@
                     int aux = nodes[parent(i)];
                     nodes[parent(i)] = nodes[i];
                     nodes[i] = aux;
-                    
+
                     rise(parent(i));
                 }
             }

}
}else if (leftChild(i) != 0){
child = leftChild(i);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -127,7 +127,7 @@
                     }
                 }else if (leftChild(i) != 0){
                     child = leftChild(i);
-                }    
+                }
                 
                 //If there's a child node, try to switch node positions
                 if(child > 0){

}else if (leftChild(i) != 0){
child = leftChild(i);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -128,7 +128,7 @@
                 }else if (leftChild(i) != 0){
                     child = leftChild(i);
                 }    
-                
+
                 //If there's a child node, try to switch node positions
                 if(child > 0){
                     if(nodes[child] < nodes[i]){

int aux = nodes[i];
nodes[i] = nodes[child];
nodes[child] = aux;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -135,7 +135,7 @@
                         int aux = nodes[i];
                         nodes[i] = nodes[child];
                         nodes[child] = aux;
-                        
+
                         descend(child);
                     }
                 }

descend(1);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -164,7 +164,7 @@
                 descend(1);
             }
         }
-        
+
     }
 
 }```


}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line contains following spacing inconsistencies:

  • No newline at EOF.

Origin: SpaceConsistencyBear, Section: all.pyjava.

The issue can be fixed by applying the following patch:

--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -167,4 +167,4 @@
         
     }
 
-}+}

@pentalpha
Copy link
Author

pentalpha commented Oct 31, 2018

There was some trailing whitespace on heap_sort.java, so I removed it in the second commit here.

@sangamcse sangamcse added the invalid This doesn't seem right label Oct 31, 2018
@sangamcse sangamcse closed this Oct 31, 2018
@pentalpha
Copy link
Author

Invalid? Why?

@sangamcse
Copy link
Member

Go through the CONTRIBUTING guideline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Algo] Heap sort [java]
2 participants