### Problem Merge Sort

I am having a problem with my merge sort. whenever I try to call merge sort on large numbers say n=10000000. It gives an error. It works fine for small numbers, even though I have declared my Lists on the heap.

The below code is just the divde part.

 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````List* Merge(List *ParentList) { if((ParentList)->Length==1) { return ParentList; } List **LeftList=new List*; *LeftList=new List; List **RightList=new List*; *RightList=new List; unsigned int Counter=0; unsigned int MidPoint=ParentList->Length/2; ListItem *TempPointer=(ParentList)->head; while(Counter!=MidPoint) { (*LeftList)->insertAtTail(TempPointer->value); TempPointer=TempPointer->next; Counter++; } //cout<<(*LeftList)->Length<insertAtTail(TempPointer->value); TempPointer=TempPointer->next; } (*LeftList)=Merge(*LeftList); (*RightList)=Merge(*RightList); return NULL; }``````
Last edited on
You already have two topics posted:
http://www.cplusplus.com/forum/general/98326/
http://www.cplusplus.com/forum/general/98326/

I'm guessing that 10,000,000 is greater than the upper limit of a signed long. Have you considered unsigned long long? (uint64_t)
Topic archived. No new replies allowed.