Can anyone help me with this StackOverFlow error? Running mergesort

* Write a description of class Sorter here.
* @author (your name)
* @version (a version number or a date)
public class Sorter
     public static long comparisons = 0;
    public static long exchanges   = 0;
    static int M = 10;
    static double aux[];
    static boolean less(double v, double w) {
       comparisons++;
       return (v < w);
    static void exch(double[] a, int i, int j) {
        exchanges++;
        double t=a; a[i]=a[j]; a[j] =t;
private static void compExch(double[] a, int i, int j)
{if (less(a[j], a[i])) exch(a,i,j);}
static int partition(double a[], int l, int r){
int i = l-1, j=r; double v = a[r];
for(;;){
while (less(a[++i],v));
while (less(v,a[--j])) if (j==l) break;
if (i >= j) break;
exch(a,i,j);}
exch(a,i,r);
return i;
static void insertion(double[] a, int l, int r)
{int i;
        for(i=r; i>l; i--) compExch(a, i-1, i);
        {int j = i; double v = a[i];
while(less(v, a[j-1]))
{a[j] = a[j-1]; j--;}
a[j] = v;
static void quicksort(double[] a, int l, int r){
if (r <= l) return;
int i = partition(a,l,r);
quicksort(a,l,i-1);
quicksort(a,i+1,r);
static void Iquicksort(double[]a, int l, int r){
if(r-l <= M) return;
exch(a, (l+r)/2, r-1);
compExch(a,l,r-1);
compExch(a,l,r);
compExch(a,r-1,r);
int i = partition(a,l+1,r-1);
Iquicksort(a,l,i-1);
Iquicksort(a,i+1,r);
static void hybridsort(double a[], int l, int r){
Iquicksort(a,l,r); insertion(a,l,r);}
static void mergeAB(double[] c, int cl, double[] a, int al, int ar, double[] b ,int bl, int br){
int i = al, j=bl;
for (int k = cl; k < cl+ar-al+br-bl+1; k++){
if (i>ar) {c[k] = b[j++]; continue;}
if (j>br) {c[k] = a[i++]; continue;}
c[k] = less(a[i], b[j]) ? a[i++] : b[j++];
static void mergesort(double[] a, int l, int r){
if (r<= 1) return;
int m=(r+1)/2;
mergesort(a,l,m);
mergesort(a,m+1,r);
merge(a,l,m,r);
static int min(int A, int B){return (A<B) ? A : B;}
static void mergesort2(double[] a, int l, int r){
if (r<=1) return;
aux = new double[a.length];
for (int m=1; m <= r-l; m=m+m)
for(int i = l; i <= r-m; i += m+m)
merge(a,i,i+m-1, min(i+m+m-1, r));
static void merge(double[]a, int l, int m, int r){
int i,j;
for (i=m+1; i>l; i--) aux[i-1] = a[i-1];
for (j=m; j<r; j++) aux[r+m-j] = a[j+1];
for (int k = 1; k <= r; k++)
if (less(aux[j], aux[i]))
a[k]=aux[j--]; else a[k]=aux[i++];
* Write a description of class SortClient here.
* 10-15-06
public class SorterClient
     public static void main(String[] args) {
int N = 1000;
int times = 1;
System.out.println("ALGORITHM comp=COMPARISONS exch=EXCHANGES");
System.out.println("---------------------------------------------------------------------------------------------");
System.out.println();
System.out.println("Selection: ");
while(times<4){
if(times==2){N=3000;}
if(times==3){N=10000;}
// generate N random real numbers between 0 and 1
long start = System.currentTimeMillis();
double[] a = new double[N];
for (int i = 0; i < N; i++)
{a[i] = Math.random();}
long stop = System.currentTimeMillis();
double elapsed = (stop - start) / 1000.0;
// sort them
Sorter test = new Sorter();
start = System.currentTimeMillis();
test.mergesort(a, 0, a.length - 1);
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.print(elapsed + "secs ");
System.out.print("N=" + N + "= ");
System.out.print(" " + Sorter.comparisons + "comp");
System.out.println(" " + Sorter.exchanges + "exch");
times++;

I get it in the mergesort method while program is running line,
mergesort(a,l,m);
quicksort runs fine.

Similar Messages

  • Can anyone help me with this 1120 error? So frustrated...

    I have those two objects homeS and galleryS and two corresponding functions to change the size of their layer masks. The structure of the two are
    exactly the same except for their names and positions. However, only one of them functions.
    The instance's name is the same in the code and there is only one key frame in the layer where movieClip "galleryMsk" is.
    But Flash always through this 1120 error saying "undefined property galleryMsk"...
    I don't know why it happens since part I is functioning perfectly.
    The only thing is that object "homeMsk" and object"galleryMsk" are in the same layer mask, does that cause the trouble?
    I am so frustrated and I cannot focus on anything else in the whole day...couldn't even sit down and watch tv happily...
    Here are the two parts of the code. Part I is working Part II is not...
    homeS.addEventListener(MouseEvent.MOUSE_OVER,f_homeDisplay);
    function f_homeDisplay(event:MouseEvent):void
              homeBtn.gotoAndPlay("home_pass");
              changeContent(homeMsk,-62.8,0);
              changeContent(homeS, -62.8,0);
              homeS.removeEventListener(MouseEvent.MOUSE_OVER,f_homeDisplay);
         }  //Part I
    galleryS.addEventListener(MouseEvent.MOUSE_OVER,f_galleryDisplay);
    function f_galleryDisplay(event:MouseEvent):void
              galleryBtn.gotoAndPlay("gallery_pass");
              changeContent(galleryMsk,-56.55,160);
              changeContent(galleryS, -56.55,160);
              galleryS.removeEventListener(MouseEvent.MOUSE_OVER,f_galleryDisplay);
         } //Part II

    never mind the paragraph at the bottom of this reply, I just got it. I found the instance galleryMsk,
    I can't upload the image now because of some strange reason,
    but it is basically a symbol with a red dot under and it says "mask3, <galleryMsk>", like this:
    Scene1
    - Symbol Definition(s)
          - buttons
              - mask3, <galleryMsk>
    It only showed the objects which are in my major scene, but all those layers are actually inside a movie clip called "buttons", I see "buttons" in the movie explorer, but I don't know how to search for the content inside...

  • HT201210 (The iPhone "Named" cannot be restored at this time because the iPhone software update server could not be contacted or is temporarily unavailable.) can anyone help me with this issue, every time i try to restore it will come up like this error m

    (The iPhone "Named" cannot be restored at this time because the iPhone software update server could not be contacted or is temporarily unavailable.)
    can anyone help me with this issue, every time i try to restore it will come up like this error message.

    Restore the iPhone when connected to iTunes by cable.
    Still the same TS1275?
    Is your iPhone jailbroken?
    Or
    Has your computer ever been used to jailbrake or downgrade (Tinyumbrella) any iPhone?

  • Can anyone help me with this message?  We could not complete your itunes store request an unknown error occurred (-1202)

    Can anyone Help me with this message?  We could not complete your itunes store request an uknown error occurred (-1201)?

    You have to unplug your ipod and reload the page.

  • Install Lightroom on a new computer - error message 2203.database Cannot open database file system error 2147287037. Can anyone help me with this?

    I am trying to install lightroom on a new computer and am getting error message 2203.database Cannot open database file system error 2147287037. Can anyone help me with this?

    This site has some info
    Error 2203 | Install | Creative Suite 4, 5, or 5.5 products or updates

  • Can someone help me with this 201435 Error during Signal Express signal generating?

    I built this signal generation tast to generate a voltage waveform. The wave form is loaded from a lvm file. (as shown in attachment pic). The waveform can be correctly viewed in preview window, so i suppose nothing wrong with the file. but when i clkick the run button, error 201435 pops up, tell me "no samples provided to DAQmx Write to initialize buffered generation".
    i dont know what step do i missed in this task. can anyone help me with this problem?

    the attachment picture
    Attachments:
    task.PNG ‏9 KB

  • HT201413 i have an iphone 3gs and everytime i try to restore it on itunes it just keeps saying an unknown erroe has occured (29) can anyone help me with this

    i have an iphone 3gs and everytime i try to restore it on itunes it just keeps saying an unknown erroe has occured (29) can anyone help me with this??

    Hello Laura,
    Thank you for posting in the Apple Support Communities.  I found an article that has information about Error 29:
    Error 20, 21, 23, 26, 28, 29, 34, 36, 37, 40
    These errors typically occur when security software interferes with the restore and update process. Follow Troubleshooting security software issues to resolve this issue. In rare cases, these errors may be a hardware issue. If the errors persist on another computer, the device may need service.
    Also, check your hosts file to verify that it's not blocking iTunes from communicating with the update server. See iTunes: Advanced iTunes Store troubleshooting—follow steps under the heading Blocked by configuration (Mac OS X / Windows) > Rebuild network information > Mac OS X > The hosts file may also be blocking the iTunes Store. If you have software used to perform unauthorized modifications to the iOS device, uninstall this software prior to editing the hosts file to prevent that software from automatically modifying the hosts file again on restart.
    You can find the full article here:
    iTunes: Specific update-and-restore error messages and advanced troubleshooting
    http://support.apple.com/kb/ts3694
    Best,
    Sheila M.

  • "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    Mine does the same thing occasionally, is your phone jailbroken? Sometimes it will work if you delete the book and reinstall it or put your phone into airplane mode then turn it back off.

  • I can't find the 2G, 3G and LTE options after updating to iOS8.1, can anyone help me with this? I'm using iPhone5s

    I can't find the 2G, 3G and LTE options after updating to iOS8.1, can anyone help me with this? I'm using iPhone5s

    I have check on my service provider about the correct APN settings, but unfortunately doesnt work still..

  • I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    Hello,
    That means it can find the Hard Drive, or can't find the things needed for booting.
    See if DU even sees it.
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

  • HT1365 Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    The figures you mention only make sense on your intranet.  Are you still using the same wireless router.  The verizon one is somewhat limited as far as max wireless-n performace.  For one thing it only has a 2.4 radio.   I like many people who wanted wireless-n performance before they even added a wireless-n gigabit router, have my own handling my wireless-n network.

  • When my screen saver has been on a while, I have to use the cursor to "rub out" part of the screen saver to see my login section. Can anyone help me with this?

    When my screen saver has been on a while, I have to use the cursor to "rub out" part of the screen saver to see my login section. Can anyone help me with this?

    I don't have a solution for you, but just wanted to let you know I used to have the exact same problem. I resolved it (for the most part....about 90% of the time, anyway) by adjusting the screensaver and power settings to never let the computer go to sleep.

  • When typing the name of the contact I want to send a text message to, names from my contact list no longer pop up as suggestions. Can anyone help me with this?

    When typing the name of the contact I want to send a text message to, names from my contact list no longer pop up as suggestions. Can anyone help me with this?

        There's always a way to reset the device jmn33! Thanks for keeping us in the loop. To process a full reset/restore on the device please visit http://vz.to/12TLCsR. Please keep us posted once this is completed, thanks!
    MatthewS_VZW
    Follow us on Twitter @VZWSUPPORT

  • My search bar for my library no longer works. Also, the menu bar is no longer visible. Noticed this problem last Saturday. Can anyone help me with this?

    My search bar for my iTunes library no longer works. Also, the menu bar is no longer visible. Noticed this problem last Saturday. This might be an issue with my desktop, and not iTunes itself Can anyone help me with this?

    Press Ctrl-B to toggle the menu bar on and off.
    When you say that the "search bar for my iTunes library no longer works" can you be more specific?  The operation of the search function has changed in iTunes 12, essentially having two very distinct modes:
    when Search Entire Library is checked, entering a search string will generate a dropdown of all matching items within your whole library, from which multiple operations are available via context menus
    when Search Entire Library is unchecked, entering a search string creates a filtered view of whatever your current focus is (e.g., if you're looking at a playlist the filter applies only to items in that playlist) with none of the dropdown options as in the first case

  • I have updated to the new version of iPhoto but it will no longer let me edit text in the preset text boxes.  The text is highlighted for a nanosecond but will not stay highlighted so I can amend it.  Can anyone help me with this.  Many thanks.

    I have updated to the latest version of iPhoto.  But now iPhoto will not let me amend the preset text in the text boxes.
    the text is highlighted for a nano second but it will not stay highlighted so that I can add my own text.
    can anyone help me with this issue.
    Many thanks

    You might try using the add-on 'NoSquint' which allows numerous zoom options specific to each page you visit & keeps your settings - https://addons.mozilla.org/en-US/firefox/addon/nosquint/
    If you want to go back to 3.6x, you will find it here:
    http://www.mozilla.com/en-US/firefox/all-older.html
    In most cases you can simply "upgrade" (meaning downgrade) directly from the installation. It would be a good idea to save your passwords & bookmarks just to be on the safe side.

Maybe you are looking for

  • Restricting PO line item quantity

    HI all, How should i restrict a PO line item quantity from RFQ Quantity? please help me how to restrict PO quantity. Thanks, Message was edited by: sungnam ko Message was edited by: sungnam ko

  • Workflow Id Hardcoding in ABAP programs

    Folks, I have always been wondering why don't we have an option of using custom workflow templates for some of the ESS services and couple other places. For example, If using Salary and Employment Verification ESS service, we have to use the workflow

  • Does the MacBook Pro with Retina Display the same ghosting issue as the 15 inch?

    I was thinking of buying a Refurbished MacBook Pro with Retina Display and heard that the 15 inch retinas have a ghosting problem. Does the 13 inch have this problem?

  • Few problems... HELP PLEASE!!!

    Two things... one, my ipod will not connect to my computer. I haven't had this problem before. I can't even plug it in to restore the ipod to delete all files to start over. Two, how do you put your ipod into disk mode? A tech said I may have a corru

  • QuickTime crashes RAID

    Hello! I've got PC with RAID (OS Vista). When I try to open JPEG or TIFF file with QuickTime Picture Viewer my computer hangs on and finally RAID is crashed. I checked Events log and found that always some error arises - Events #9, source: iaStor. I