Mình cài đặt Mergesort bằng DSLK kép nhưng khi chạy VS C++ báo lỗi
Windows has triggered a breakpoint in Mergesort.exe.

This may be due to a corruption of the heap, which indicates a bug in Mergesort.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Mergesort.exe has focus.

The output window may have more diagnostic information.
Rất mong các bạn chỉ sửa giúp.
C++ Code:
  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<iostream>
  4. #include<stdlib.h>
  5. using namespace std;
  6. typedef struct tag_NODE
  7. {
  8.     int data;
  9.     struct tag_NODE* pNext;
  10.     struct tag_NODE *pPrev;
  11. }NODE;
  12. typedef struct tag_LIST
  13. {
  14.     NODE *pHead;
  15.     NODE *pTail;
  16. }LIST;
  17. void khoitao(LIST &l)
  18. {
  19.     l.pHead=l.pTail=NULL;
  20. }
  21. NODE * tao_nut(int x)// tao 1nut de chua du lieu
  22. {       NODE *p;
  23.         p=new NODE;
  24.         if(p==NULL)
  25.         {cout<<"\n khong du bo nho:";
  26.         _getch();
  27.         exit(0);
  28.         }
  29.         p->data=x;
  30.         p->pNext=NULL;
  31.         p->pPrev=NULL;
  32.         return p;
  33. }
  34. void tao_ds(LIST &l)// gan nut vao dslk
  35. {   int x;NODE *p;
  36.     do
  37.     {
  38.     cout<<"\n nhap so nguyen, de thoat nhap -1, x= ";
  39.     cin>>x;
  40.     if(x==-1)
  41.     break;
  42.     p=tao_nut(x);
  43.     if(l.pHead==NULL)
  44.     l.pHead=l.pTail=p;
  45.     else
  46.     {
  47.         l.pTail->pNext=p;
  48.         p->pPrev = l.pTail;
  49.         l.pTail=p;
  50.     }
  51.     }while(1);
  52. }
  53. void xuat(LIST l)//in ds ra man hinh
  54. {  
  55.     for(NODE *p=l.pHead;p;p=p->pNext)
  56.     {
  57.     cout<<p->data<<" -> ";
  58.     }
  59.     cout<<"NULL\n";
  60. }
  61.  
  62. void themcuoi(LIST &l,NODE *p)// chen nut vao cuoi ds
  63. {  
  64.     if(l.pTail==NULL)
  65.         l.pHead=l.pTail=p;
  66.     else
  67.     {
  68.         l.pTail->pNext=p;
  69.         p->pPrev=l.pTail;
  70.         l.pTail=p;
  71.     }
  72. }
  73. int  xoadau(LIST &l)
  74. {  
  75.     if ( l.pHead == NULL)
  76.         return 0;  
  77.     NODE *p = l.pHead;
  78.     l.pHead = l.pHead->pNext;
  79.     delete p;
  80.     if (l.pHead != NULL)
  81.         l.pHead->pPrev = NULL;
  82.     else    l.pTail = NULL;
  83.     return 1;    
  84.  
  85. }
  86. int xoacuoi(LIST &l)
  87. {  
  88.     if (l.pTail == NULL)
  89.         return 0;
  90.     NODE *p = l.pTail;
  91.     l.pTail = l.pTail->pPrev;
  92.     delete p;
  93.     if (l.pTail != NULL)
  94.         l.pTail->pNext = NULL;
  95.     else    
  96.         l. pHead = NULL;    
  97.     return 1;
  98. }
  99.  
  100. void Chia_DS(LIST &l,LIST &ds1, LIST &ds2)
  101. {
  102.     NODE *p,*q;
  103.     while (l.pHead!=l.pTail)
  104.     {
  105.         p=l.pHead;
  106.         xoadau(l);
  107.         p->pNext=NULL;
  108.         p->pPrev=NULL;
  109.         themcuoi(ds1,p);
  110.         q=l.pTail;
  111.         xoacuoi(l);
  112.         q->pNext=NULL;
  113.         q->pPrev=NULL;
  114.         themcuoi(ds2,q);
  115.     }
  116.     if(l.pHead)
  117.     {
  118.         p=l.pHead;
  119.         xoadau(l);
  120.         p->pNext=NULL;
  121.         p->pPrev=NULL;
  122.         themcuoi(ds1,p);
  123.     }
  124. }
  125.  
  126. void tron2DS(LIST &l,LIST  &ds1,LIST &ds2)// noi cac danh sach con lai
  127. {
  128.     NODE *p=new NODE;
  129.     while((ds1.pHead!=NULL) && (ds2.pHead!=NULL))
  130.     {
  131.         if(ds1.pHead->data <= ds2.pHead->data)
  132.         {
  133.             p=ds1.pHead;
  134.             ds1.pHead=ds1.pHead->pNext;
  135.            
  136.         }
  137.         else
  138.         {
  139.             p=ds2.pHead;
  140.             ds2.pHead=ds2.pHead->pNext;
  141.         }
  142.         p->pNext=NULL;
  143.         p->pPrev=NULL;
  144.         themcuoi(l,p);
  145.     }
  146.     if(ds1.pHead)
  147.         {
  148.        
  149.             ds1.pHead->pNext=l.pTail;
  150.             l.pTail->pNext=ds1.pHead;
  151.             l.pTail=ds1.pTail;
  152.         }
  153.     else
  154.         {
  155.             ds1.pHead->pNext=l.pTail;
  156.             l.pTail->pNext=ds1.pHead;
  157.             l.pTail=ds1.pTail;
  158.         }
  159. }
  160.  
  161. void Mergesort(LIST &l)
  162. {
  163.      LIST ds1,ds2;
  164.      khoitao(ds1);
  165.      khoitao(ds2);
  166.     if(l.pHead==l.pTail)
  167.        return;
  168.     Chia_DS(l,ds1,ds2);
  169.     cout<<"\n Xuat ds 1 test trong ham merge: ";
  170.     xuat(ds1);
  171.     _getch();
  172.     cout<<"\n Xuat ds 2 test trong ham merge:: ";
  173.     xuat(ds2);
  174.     _getch();
  175.     Mergesort(ds1);
  176.     Mergesort(ds2);
  177.     tron2DS(l,ds1,ds2);
  178. }
  179.  
  180. void main()
  181. {
  182.     LIST l;
  183.     khoitao(l);
  184.     tao_ds(l);
  185.     cout<<"\nDanh sach vua nhap vao: ";
  186.     xuat(l);
  187.     Mergesort(l);
  188.     cout<<"\nKet Qua khi mergesort: ";
  189.     xuat(l);
  190.     _getch();
  191. }