## 你们怎么解决栈堆溢出

870177103 发布于 2013/03/08 13:44

0
8
typedef PDATA *PPDATA ; //#define QUICKSORT_QUICKSORT_A #ifndef QUICKSORT_QUICKSORT_A #define QUICKSORT_QUICKSORT_B #endif #ifdef QUICKSORT_QUICKSORT_A int QuickSort (const PDATA pdtArr ,const COUNT ctArr) { DATA dtTemp ; PDATA pdtFirst ,pdtLast ,pdtLeft ,pdtRight ; PPDATA ppdtPeek ; ppdtPeek = (PPDATA) malloc (ctArr & 0X00000001 ? ctArr + 8 : ctArr + 4) ; *ppdtPeek = NULL ; pdtLeft = pdtArr ; pdtRight = pdtArr + ctArr - 1 ; do { pdtFirst = pdtLeft ; pdtLast = pdtRight ; while (TRUE) { #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtLeft++ ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtRight-- ; #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtRight-- ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtLeft++ ; } if (pdtLeft > pdtFirst AND pdtRight < pdtLast) { pdtLeft = pdtFirst ; pdtRight-- ; *++ppdtPeek = pdtLast ; } else do { pdtLeft = pdtLast + 2 ; pdtRight = *ppdtPeek-- ; } while (pdtLeft == pdtRight) ; } while (pdtRight != NULL) ; return 0 ; } #else int QuickSort (const PDATA pdtArr ,const COUNT ctArr) { void Quick (const PDATA pdtFirst ,const PDATA pdtLast) ; if (pdtArr == NULL OR ctArr < SORT_CTARR_MIN OR ctArr > SORT_CTARR_MAX) //Check Inlegal Parameters return ERROR ; const PDATA pdtFirst = pdtArr ; const PDATA pdtLast = pdtArr + ctArr - 1 ; Quick (pdtFirst ,pdtLast) ; return 0 ; //Return Successfully } void Quick (const PDATA pdtFirst ,const PDATA pdtLast) { DATA dtTemp ; PDATA pdtLeft ,pdtRight ; pdtLeft = pdtFirst ; pdtRight = pdtLast ; while (TRUE) { #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtLeft++ ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtRight-- ; #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtRight-- ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtLeft++ ; } pdtLeft-- ; pdtRight++ ; if (pdtLeft > pdtFirst AND pdtRight < pdtLast) { Quick (pdtFirst ,pdtLeft) ; Quick (pdtRight ,pdtLast) ; } return ; } #endif
0

#### 引用来自“870177103”的答案

typedef PDATA *PPDATA ; //#define QUICKSORT_QUICKSORT_A #ifndef QUICKSORT_QUICKSORT_A #define QUICKSORT_QUICKSORT_B #endif #ifdef QUICKSORT_QUICKSORT_A int QuickSort (const PDATA pdtArr ,const COUNT ctArr) { DATA dtTemp ; PDATA pdtFirst ,pdtLast ,pdtLeft ,pdtRight ; PPDATA ppdtPeek ; ppdtPeek = (PPDATA) malloc (ctArr & 0X00000001 ? ctArr + 8 : ctArr + 4) ; *ppdtPeek = NULL ; pdtLeft = pdtArr ; pdtRight = pdtArr + ctArr - 1 ; do { pdtFirst = pdtLeft ; pdtLast = pdtRight ; while (TRUE) { #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtLeft++ ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtRight-- ; #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtRight-- ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtLeft++ ; } if (pdtLeft > pdtFirst AND pdtRight < pdtLast) { pdtLeft = pdtFirst ; pdtRight-- ; *++ppdtPeek = pdtLast ; } else do { pdtLeft = pdtLast + 2 ; pdtRight = *ppdtPeek-- ; } while (pdtLeft == pdtRight) ; } while (pdtRight != NULL) ; return 0 ; } #else int QuickSort (const PDATA pdtArr ,const COUNT ctArr) { void Quick (const PDATA pdtFirst ,const PDATA pdtLast) ; if (pdtArr == NULL OR ctArr < SORT_CTARR_MIN OR ctArr > SORT_CTARR_MAX) //Check Inlegal Parameters return ERROR ; const PDATA pdtFirst = pdtArr ; const PDATA pdtLast = pdtArr + ctArr - 1 ; Quick (pdtFirst ,pdtLast) ; return 0 ; //Return Successfully } void Quick (const PDATA pdtFirst ,const PDATA pdtLast) { DATA dtTemp ; PDATA pdtLeft ,pdtRight ; pdtLeft = pdtFirst ; pdtRight = pdtLast ; while (TRUE) { #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtLeft++ ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtRight-- ; #ifdef SORT_ZORDER_DOWN while (*pdtLeft > *pdtRight AND pdtLeft < pdtRight) #else while (*pdtLeft < *pdtRight AND pdtLeft < pdtRight) #endif pdtRight-- ; if (pdtLeft >= pdtRight) break ; if (*pdtLeft != *pdtRight) { dtTemp = *pdtLeft ; *pdtLeft = *pdtRight ; *pdtRight = dtTemp ; } pdtLeft++ ; } pdtLeft-- ; pdtRight++ ; if (pdtLeft > pdtFirst AND pdtRight < pdtLast) { Quick (pdtFirst ,pdtLeft) ; Quick (pdtRight ,pdtLast) ; } return ; } #endif

0
8