Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. BALANCED merge sort

BALANCED merge sort

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sadas232341s
    wrote on last edited by
    #1

    What does that mean, and what is the difference between just merge sort? Here is the code I use for just merge sort. How to make it BALANCED.

    void Merge(int arr[], int low, int high, int mid)
    {
    int i, j, k, c[50];

    i = low;
    j = mid + 1;
    k = low;
    
    while((i <= mid) && (j <= high))
    {
    	if(arr\[i\] < arr\[j\])
    	{
    		c\[k\] = arr\[i\];
    		
    		k++;
    		i++;
    	}
    	else
    	{
    		c\[k\] = arr\[j\];
    		
    		k++;
    		j++;
    	}
    }
    
    while(i <= mid)
    {
    	c\[k\] = arr\[i\];
    	
    	k++;
    	i++;
    }
    
    while(j <= high)
    {
    	c\[k\] = arr\[j\];
    	
    	k++;
    	j++;
    }
    
    for(i = low; i < k; i++)
    {
    	arr\[i\] = c\[i\];
    }
    
    UpdateData(arr, high + 1);
    

    }

    void MergeSort(int arr[], int low, int high)
    {
    int mid;

    if(low < high)
    {
    	mid = (low + high) / 2;
    	
    	MergeSort(arr, low, mid);
    	MergeSort(arr, mid + 1, high);
    	
    	Merge(arr, low, high, mid);
    
    	SwapsCount++;
    }
    

    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups