• 0

Finding Median/Mode by Recursion


Question

3 answers to this question

Recommended Posts

  • 0

You would arrange the numbers in ascending or descending order using a bubble sort while incrementing a variable each time to show how many there are. Then after that you would just divide by half once and then exit prog (doesnt make much sense but there isnt really any other way to get out of the recursiveness from what i know. It would go something like this (for median):

int sortmedian()
{
int temp;
static int count = 0; ?//this variable never loses value
if(arrayofints[count] > arrayofints[count + 1]
{
temp = arrayofints[count];
arrayofints[count] = arrayofints[count + 1];
arrayofints[++count] = temp;
} ?//function SHOULD (not will) keep sorting array to make values incrementing
sortmedian();
return count/2;
}

i havent worked with recusive functions almost ever so there are almost definitely errors in there, but if there are and you find / fix them, could u plz post the final vers. here, i wanna learn more. Oh and if anyone knows how to do the mode, plz post, cuz i figure it would be very manual but im sure there is some way to do it without making custom variables.

Edited by super_serge
  • 0

to find the mode, recursively, you need a recursive sort

i suggest quicksort / mergesort to name just 2 - there are more recursive sorting algorithms

do a google on quicksort

to find the median, first sort the data using above techniques, and then take the middle datum

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • OneDrive for Mac now lets you sync files to removable drives by Taras Buria If you use OneDrive on Mac and often work with external drives (a common sight among Mac users where internal storage is not upgradeable), Microsoft has some good news for you: the OneDrive client for macOS now supports removable drives, allowing you to sync files to external disks, both non-removable and removable. Microsoft introduced external drive support in OneDrive for Mac at the beginning of 2025. However, the initial rollout was limited to drives that macOS detects as non-removable. The company received plenty of feedback from users regarding this change, and it is now addressing the inability to sync files to removable drives. External drive support in OneDrive works the same way as syncing files to internal storage. If you unplug your drive, say, a portable SSD, OneDrive will stop syncing and notify you with an error message (there is a short delay for drives that sporadically disconnect). To resume sync, reconnect your drive and restart OneDrive. If you want to sync OneDrive to an external drive, your drive should be formatted for APFS (Apple File System) and protected by FileVault (read-only, network, and quarantined drives are not supported). Also, you need macOS version 15.0 or newer and OneDrive version 25.097 or newer. For now, external drive support is only available for insiders, but a wider rollout is coming soon. Finally, Microsoft adds that external drive support does not allow moving drives between devices. Therefore, you must set up OneDrive sync again every time you connect your drive to a new Mac. You can read more about external drive support in OneDrive for Mac in a post on the official Tech Community website. In other OneDrive news, check out our recently published guide, which details how to change OneDrive folder colors for extra personalization.
    • I'm here for it! Bill Pullman & Rick Moranis Returning For New ‘Spaceballs’; Keke Palmer Also Set https://deadline.com/2025/06/spaceballs-2-casts-rick-moranis-bill-pullman-keke-palmer-1236431204/ It's gonna be epic! 
    • Lipstick on a data-hungry pig...
    • I really feel like we need a 3rd good phone OS option to compete with Google and Apple.
    • After 40 years we asked what the fans want...... and are making this movie anyway! 
  • Recent Achievements

    • One Month Later
      POR2GAL4EVER earned a badge
      One Month Later
    • One Year In
      Orpheus13 earned a badge
      One Year In
    • One Month Later
      Orpheus13 earned a badge
      One Month Later
    • Week One Done
      Orpheus13 earned a badge
      Week One Done
    • Week One Done
      serfegyed earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      536
    2. 2
      ATLien_0
      260
    3. 3
      +FloatingFatMan
      203
    4. 4
      +Edouard
      168
    5. 5
      Xenon
      124
  • Tell a friend

    Love Neowin? Tell a friend!