Apr 10, 2013 at 6:05pm UTC
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
List<long >* Merge(List<long > *ParentList)
{
if ((ParentList)->Length==1)
{
return ParentList;
}
List<long > **LeftList=new List<long >*;
*LeftList=new List<long >;
List<long > **RightList=new List<long >*;
*RightList=new List<long >;
unsigned int Counter=0;
unsigned int MidPoint=ParentList->Length/2;
ListItem<long > *TempPointer=(ParentList)->head;
while (Counter!=MidPoint)
{
(*LeftList)->insertAtTail(TempPointer->value);
TempPointer=TempPointer->next;
Counter++;
}
//cout<<(*LeftList)->Length<<endl;
while (TempPointer!=NULL)
{
(*RightList)->insertAtTail(TempPointer->value);
TempPointer=TempPointer->next;
}
(*LeftList)=Merge(*LeftList);
(*RightList)=Merge(*RightList);
return NULL;
}
Last edited on Apr 10, 2013 at 6:07pm UTC