This will get you using your head.

Hi,
I am trying to convert a search algorithm so it will iterate one step at a time every time the method is called instead of doing the whole sort at once. I have done it with a bubble sort
FROM:
     public static void bubble(int bNumbers[])
          int i, j, temp;
          for (i = (bNumbers.length - 1); i >= 0; i--)
               for (j = 1; j <= i; j++)
                    if (bNumbers[j-1] > bNumbers[j])
                         temp = bNumbers[j-1];
                         bNumbers[j-1] = bNumbers[j];
                         bNumbers[j] = temp;
     }INTO
     public static void bubble(int bNumbers[])
          if(jB != 10)
               int temp;
               if (bNumbers[jB-1] > bNumbers[jB])
                    temp = bNumbers[jB-1];
                    bNumbers[jB-1] = bNumbers[jB];
                    bNumbers[jB] = temp;
               if(jB==iB)
                    jB=0;
                    iB--;
               jB++;
     }I am trying to do the same with an insertion sort. I have been trying for the last 2 hours and it is reallying starting to annoy me. Can anyone have a go.
Insertion Sort algorithm:
     public static void insertion(int iNumbers[])
          int i, j, index;
          for (i=1; i < iNumbers.length; i++)
               index = iNumbers;
               j = i;
               while ((j > 0) && (iNumbers[j-1] > index))
                    iNumbers[j] = iNumbers[j-1];
                    j = j - 1;
               iNumbers[j] = index;
Thanks
John Cleary.

Sounds like a producer-consumer scenario. I have done some animation out of some graph algorithms, and here is what I did for a step-by-step execution.
I used a separate thread for the algorithm, and it checked a flag to see if the user wanted step by step execution, and if so it waited on a lock. When the user signaled for another step, it was just
lock.notify();
Is that ok for you?

Similar Messages

  • If you use your iPod Touch while its charging, will it ruin the battery life/battery?

    I have an iPod Touch 5th gen. and people say that if you use your iPod/iPhone while its charging, the battery life will deacrease or the battery will be ruined/shot

    However, you should almost fully discharge and fully charge the battery monthly otherwise you will degrade the battery.
    Apple - Batteries - iPod

  • Does anybody know how to download songs without having to pay for them when you use your voucher. I have redeemed it and have £15 in my account yet everytime I go to download a song it's trying to get me to pay!!! Please help?

    Does anybody know how to download songs without having to pay for them when you use your voucher. I have redeemed it and have £15 in my account yet everytime I go to download a song it's trying to get me to pay!!! Please help?

    hiya. thanks for your suggestion. i just tried it and it worked so thanks XD
    i wish apple would make an "exclude" option though tbh.
    i have some others called ... in the name "...soundtrack" (one word) or "hidden track" and "teaching track" !
    i've got another one literally called "track by track walk through" lol
    now im wishing there was just an option to select these oddballs and exclude them individually.
    i cant come up with rules for every single possibility, but i cannnn eliminate those odd songs when i see them if there was an exclude option.
    but thanks anyway xx

  • How do you use your iPod Touch?

    I'm thinking of buying an ipod touch 5th gen, but I have to convince myself that it would help me significantly before I drop $300 on a device. My question: how do you use your iPod Touch, aka, what things have helped you significantly, excluding games? I've heard a ton about how awesome the new version is, and everything about its camera and retina display, but I want to know that I would actually use one first....
    Thanks.

    Surf the web from bed and coffee shops/bookstores.  When in a store that has WiFi I may research a product that looks interesting to buy.
    It is a camera that is always with you (assuming you always take it with you), so you can capture that picture that happens once in a life time.  Also the camera is great when shopping for "Big Ticket" items as you can take pictures to remind you of things you were looking at so you can do additional research at home before making your final decision.
    Check my mail from bed and coffee shops/bookstores, etc... when WiFi is available.
    Use it as an alarm clock, meeting reminder, todo reminder.
    Take notes (not school notes, just ideas, stuff I maybe want to buy, useful information I may pick up in a bookstore, books I may want to buy, etc...)
    Contains my contacts for friends, family, and businesses (plumber, dentist, doctor, etc...)
    Plays music, or in my case, I listen to podcasts
    Reading ebooks.  I use it a lot to read ebooks.  It is always with me, so I can read a book anywhere, such as waiting in a doctor/dentist office, at the motor vehicle registry.  And reading in bed is great as when you fall asleep, it remembers what page you were on vs that book that drops onto your face and wakes you back up while at the same time loosing your page
    The Maps app is great for finding where something is located, and plotting how to get there (not as good as having an iPhone with GPS, but still useful).  Also the satellite images make it easier to visualize where you are going.
    When connected to WiFi it can be used for Facetime when calling a friend or family member that also has an iOS device.  Seeing a loved one when they are not near can be emotionally satisfying.  You can also make skype calls.
    I use 1Password to store all my passwords.  It keeps them secure, I always have them with me, and I do not need to use the same password over and over again, or make them too simple to remember.  1Password has a built-in browser so you it can substitute the correct password for the web site you are visting without actually needing to look it up.
    1Password related but not passwords.  Because 1Password encrypts all the data it holds, I can also store sensitive information (such as medical conditions, or other information I do not want made public should my device be lost or stolen), yet always have that information with me should I need it.
    I can get the weather.  This week, I've been using an app to get high/low Tide infromation, plus sunrise information.  But getting weather info when you wake up so you can plan your day and if you need to shovel the driveway before going to work.  I find it easier to get the weather from my iOS device than it is to use my laptop or turn on the Weather Channel.
    Calclator.  2+2 = 4, but there are times you do need to get something right, and calculators are useful. They have all kinds available, including hexidecimal calculators for programmers.
    RSS newsfeed reader (I follow about 20+ feeds, including these discussions groups via RSS feeds).
    Travel services.  Most airports have WiFi, and you can get updated travel info for your flights via some speciallized travel apps.
    If you are into tracking your car mileage, gas usage, maintenance costs, etc..., there are apps for that.
    While you can watch video on your iOS device (downloaded movies, YouTube), you can also stream movies from services such as Netflix.  This can be useful when traveling, or if you are stuck in bed with a cold, or if you have lost control of the "Remote" and do not want to watch "Dancing with the Stars"
    TV related, there are apps that will give you the TV schedule for your area, so you can browse the shows on this evening.
    List.  You can keep lists, including grocery shopping lists, items to pack for a trip lists, things to do for that bathroom remodel, things you need to get before school starts, Christmas lists, etc....  NOTE:  Ideas for Christmas/Birthday/Anniversary gifts may come anytime during the year, but if you do not write them down, you may be scratching your head when the event arrives.  Putting them in a list can help you later on.
    You can get a Level app.  You may laugh, but I have actually used my iOS device to check if something was level.  It was there, and a carpenters level was not.  Not perfect, but it did what I needed at the time.
    Finding a good resturante (Yelp, Urbanspoon, etc...).  The iOS device can be very helpful in finding a good nearby place to eat when away from home, or even discovering a new play where you live to get out of that eat at the same place rut.
    That is some of the things I use my iOS device for.

  • Does anyone know when the ball will be picked up and Canada users will get full use of siri ?

    Does anyone know when the ball will be picked up and Canada users will get full use of siri ?

    No, since we're users just like you.  You'll have to wait for Apple to announce it.  Speculation is prohibited by the Terms of Use of this forum.

  • Can you use your imac as a monitor for you mac book pro laptop?

    Can you use your imac as a monitor for you mac book pro laptop?
    I have two computer one being a new mac book pro and the other being a slightly older imac desktop. I am wanting to know if you can use the desktop as a screen for my mac book pro. I just to mirror the laptop onto the desktop because it is more powerful, instead of getting another display for my laptop.
    Is this possible and what connections do I need?
    Thanks

    Hello, we need more info on the iMac, not positive but I think it requires a 2010 or newer iMac & a Mini Display Port cable.
    So we know more about it...
    At the Apple Icon at top left>About this Mac, then click on More Info, then click on Hardware> and report this upto but not including the Serial#...
    Hardware Overview:
    Model Name: iMac
    Model Identifier: iMac7,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 4 MB
    Memory: 6 GB
    Bus Speed: 800 MHz
    Boot ROM Version: IM71.007A.B03
    SMC Version (system): 1.21f4

  • TS3510 how do you use your apple ID email with facetime on your laptop and your iphone?

    I am trying to set up my Facetime on my laptop and it's telling me that my email is already being used (from my iphone facetime). Can you use your Apple ID email AND iphone accounts in for both FaceTimes?

    That's normal. Just enter your password. You won't be able to change the Apple ID that appears there. After you sign out, and sign in with the new Apple ID, it will take the place of the old one.
    If you changed your Apple ID password, enter the new password.
    There are many iCloud services, and you might be confronted with the old Apple ID as you use them. You might have to sign out of each one individually, and sign in under your revised Apple ID.
    I agree it's confusing. It's even more confusing if you created more than one Apple ID. That's a different circumstance from changing an Apple ID. I hope you didn't do that.

  • I have a problem that I try to turn on the iPad 2, but he was just lighting up, but nothing is displayed. I do not know what happened, but yesterday did not do this. Thank you for your help.

    I have a problem that I try to turn on the iPad 2, but he was just lighting up, but nothing is displayed. I do not know what happened, but yesterday did not do this. Thank you for your help.

    Try reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    Note: Data will not be affected.

  • HT1947 Can you use your iPad alone for sharing iTunes music to apple tv without having your pc on?

    Can you use your iPad alone to share iTunes music to apple tv without having to use your pc?

    Do you have any music stored on your iPad or is it all on your PC?
    If the music is stored on your iPad, then double tap the home button, swipe (left to right motion) and you will see the volume/brightness controls/AirPlay. Tap on AirPlay and select ATV. Then go into the music app

  • The more times you use your charger the less efficient it becomes?

    So is this true?
    I heard somewhere that the more times you use your laptop charger, the less effiecient (i.e. slower to charge) it becomes.
    I also heard it is very bad for the charger(as well as the environment) to leave it plugged in while its not in use.
    Can anyone shed some light on this?

    Neither of these crackbrained notions is true, though the adapter does draw about one watt of AC power when it's plugged in and nothing is connected to it. Leaving it like that 24/7 would run your electric bill up by nearly a third of a cent per day, if you never plugged the MagSafe into your computer at all. Whatever else you're doing with your life has a heckuva lot more impact on the environment than that does.

  • When I try to save a document a message comes up saying "Couldn't auto-save document." How can I fix this? Thank you for your help!

    When I try to save a document a message comes up saying "Couldn't auto-save document." How can I fix this? Thank you for your help! - Chip

    This is a mean one. I don't have time to try and find the cause, but at least some answers to your questions, to hopefully shed some more light on this.
    Where was the original destination? iCloud folder.
    On another drive? Tried to Save as... to Hard Drive (also changing name of file), always get the same non-descript short Error "Couldn't auto-save document." (slides down from top with a yellow warning triangle). Status to the right of document name is "Not Saved".
    Another Server? No access at this time.
    I also tried File, Revert to, Browse all versions, to check what I'd be losing. Saw I wasn't losing much and selected the last version and pressed Restore - same error. In the end I just quit Pages and re-opened. The document opened with the last few edits missing (but with the status "Edited" next to the name). I re-edited and could save. Good old habit of saving often.

  • If you use your home wifi, can your parents see your iMessages?

    I'm just wondering if you use your home wifi can your parents see your iMessages?

    Nobody can see your iMessages unless you let them (leave the device unlocked, set the account up on another device they have access to, have messages popup on the lock screen). It has nothing to do with where or how you use iMessage.

  • If you use your apps does it use data, such as angry birds?

    Do you use data if you use your apps, such as angry birds.(i see advertisement while i'm playing)

    For an ad to download and be available requires internet access, but unless you select the ad the size of the download is quite small.

  • Firefox any version Mac, has a bug were it does not see or ask for the proxy username and password. This happens if you use a virtual tagged interface.

    Firefox any version Mac, has a bug were it does not see or ask for the proxy username and password. This happens if you use a virtual tagged interface. A recent network University policy change. The only way to fix this, is if you use a manual proxy configuration in Firefox. So all 100 + uni iMac's can only use Safari as I would need to do a profile push to all 300 students and I am unsure what file carries the proxy information.

    Firefox any version Mac, has a bug were it does not see or ask for the proxy username and password. This happens if you use a virtual tagged interface. A recent network University policy change. The only way to fix this, is if you use a manual proxy configuration in Firefox. So all 100 + uni iMac's can only use Safari as I would need to do a profile push to all 300 students and I am unsure what file carries the proxy information.

  • When you use your iPhone hotspot..

    When you use your iPhone hotspot do you have to pay? I have a 4s and an ipod 5 and i connected them so I can use my ipod for long distances.... so do i have to pay for that?

    hey! thanks! uhmm. so one more thing.. can you only use it when the devices are close to each other? can you use it when both devices are far apart?? thanks

Maybe you are looking for

  • Lumix G3 raw files?

    When will Aperture support Panasonic Lumix raw files?

  • PSE 3 In CoverFlow : Transparency never holds !

    _Even The Missing Manual for PSE # tells me that .TIFFs and jPeg 2000 should retain their transparency, but quit / reopen iTunes & it's filled in white or black ! It's an amazing effect to have a lit or framed logo / image suspended there in CoverFlo

  • How to sync without losing artwork

    I turned on match on devices and now with itunes it's a pain to get artwork sync between itunes on imac and my ipod touch, The ipod loses a lot of album artwork. What did apple di with itunes? can't now drag an album to ipod touch and get it there wi

  • Yosemite install problem, Lightroom 5.6

    Hello, I've a installation problem on Yosemite system. At the first start, after install package and activate product, i've error message (I'm French user) : "Une erreur s'est produite lors de la tentative de changement de modules." I can translate t

  • Joining a Windows 2000 domain

    Can I join my Sun Solaris 8 server running Samba to a Windows 2000 domain so that all the users that logon or use shares will authenticate thru the domain controllers with their Win accounts? I dont want to create 1500 Solaris accounts.