Results 1 to 3 of 3

Thread: mergeSort

  1. #1
    Blue_beaver is offline Member
    Join Date
    Feb 2009
    Location
    Montreal
    Posts
    5
    Rep Power
    0

    Default mergeSort

    in class, the teacher showed us the mergeSort recursive algorithm.

    I tried to implement it, but for some reasons, it erases the array somehow.

    The way i implemented it was to create a class Sortable and methods that i could use on a Sortable object like this:
    ____
    int[] test = new int[] {3,1,2};
    Sortable = new Sortable(test);
    test.mergeSort;
    _____

    Here's my code:

    java
    .pastebin.
    com/
    m77def8af

    Here's the algorithm in pseudo code:

    freepdfhosting.
    com/
    db1d6d7d61.pdf

    HELP! ;_;

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    You didn't implement the psudocode exactly. Check your merge function against the psudocode, line by line, your mistake lies there.

    A hint, did you know that uninitialized values in an int array are set to zero? What happened isn't that your array was erased, but instead you copied a bunch of zero values over the correct values. So, where in your code did you copy values from an uninitialized array? And, did you mean to copy all the values that you copied?
    Last edited by CodesAway; 10-10-2009 at 06:18 AM.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    Blue_beaver is offline Member
    Join Date
    Feb 2009
    Location
    Montreal
    Posts
    5
    Rep Power
    0

    Default

    Thank you so much for this perfect answer: the hint was EXACTLY what i was missing.

    Thank you so much again. :D

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •