Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-2008, 12:02 PM
felixb felixb is offline
Newbie
 
Join Date: Mar 2008
Posts: 7
Rep Power: 0
felixb is on a distinguished road
Default recursive merge

Hello,

I wrote a merge function,
can you help me to write recursive version to my merge function?
(i dont know how to do it)

c++ Code:
  1. void merge(int* arr, int size)
  2. {
  3.    int* temp;
  4.    int* side1=arr;
  5.    int* side2=arr+size/2;
  6.    int i;
  7.  
  8.    temp=(int*)malloc(size*sizeof(int));
  9.    checkAlloc(temp);
  10.  
  11.    while((side1<arr+size/2)&&(side2<arr+size))
  12.    {
  13.          if(*side1<*side2)
  14.          {
  15.     *temp=*side1;
  16.     temp++;
  17.     side1++;
  18.          }
  19.          else
  20.          {
  21.     *temp=*side2;
  22.     temp++;
  23.     side2++;
  24.          }
  25.    }
  26.  
  27.    while(side1<arr+size/2)
  28.    {
  29.        *temp=*side1;
  30.         temp++;
  31.         side1++;
  32.    }
  33.    while(side2<arr+size)
  34.    {
  35.        *temp=*side2;
  36.         temp++;
  37.         side2++;
  38.    }
  39.    temp=temp-size;
  40.  
  41.    for(i=0;i<size;i++)
  42.   {
  43.       *(arr+i)=*(temp+i);
  44.   }
  45.   free(temp);
  46. }

Last edited by Jaan; 04-01-2008 at 12:06 AM. Reason: Please use tags when you're posting your code!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-29-2008, 04:05 PM
dcs dcs is offline
Learning Programmer
 
Join Date: Mar 2008
Posts: 60
Rep Power: 2
dcs will become famous soon enough
Default Re: recursive merge

Eternally Confuzzled - The Art of Sorting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-29-2008, 06:01 PM
felixb felixb is offline
Newbie
 
Join Date: Mar 2008
Posts: 7
Rep Power: 0
felixb is on a distinguished road
Default Re: recursive merge

no... this is the regular merge.
what I ask is about making the merge function recursive...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-31-2008, 02:26 AM
felixb felixb is offline
Newbie
 
Join Date: Mar 2008
Posts: 7
Rep Power: 0
felixb is on a distinguished road
Default Re: recursive merge

some one can help?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-01-2008, 12:44 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,736
Last Blog:
Passwords
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Re: recursive merge

Chinmoy wrote a pretty good tutorial on recursion here: recursion

Give it a read, and if you have a specific question we will be more than happy to assist - but I doubt you will find someone who will rewrite your entire algorithm.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Blogs? Combine RSS? Shan Abbasi Website Design 7 01-10-2008 10:44 AM


All times are GMT -5. The time now is 12:05 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads