1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Checking Program

  1. Jan 31, 2005 #1
    Hello all:

    My program for MergeSort is not working. It keeps saying that Mege is undefined. Here is my code:

    Code (Text):
     public class MergeSort extends Merge {
    public static void mergeSort(int[] a, int first, int last) {

            if(last==first) return;
            if (last - first == 1) {
                //  not a[0]>a[1]; this part could test on the upper half of the array
                if (a[first] > a[last]) {
                    int temp = a[first];
                    a[first] = a[last];
                    a[last] = temp;
                }
               

            } else {
                int halfwayPoint = (int) (last + first) / 2;
                mergeSort(a, first, halfwayPoint);
                mergeSort(a, halfwayPoint + 1, last);
                merge(a, first, last, halfwayPoint);

            }
        }
    }
     
    How should I fix this problem? Any ideas are greatly appreciated.

    Thanks :smile:
     
  2. jcsd
  3. Jan 31, 2005 #2

    learningphysics

    User Avatar
    Homework Helper

    The "extends Merge" seems to be the problem. Are you trying to subclass another class Merge? If not, then just get rid of the "extends Merge".

    You also need to define the function merge, which will merge together an array whose upper and lower halfs are sorted.
     
    Last edited: Jan 31, 2005
  4. Jan 31, 2005 #3
    It seems that you are trying to create a child class without having declared a parent class (if U know what I mean). You cannot write "extends Merge" without having declared a class called Merge. If that's not what you're trying to do (class hierarchy, I mean), just get rid of the "extends Merge" on the header. There's no point in creating a parent-child class relationship if the child does not need to inherit anything from the parent class.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Checking Program
  1. Tension check (Replies: 7)

  2. Checking Vectors (Replies: 13)

  3. Momentum check (Replies: 1)

  4. Checking answers? (Replies: 1)

  5. Kinimatics check (Replies: 4)

Loading...