#include "stdio.h" /*构件(双向、循环)链表*/ struct MonkeyNo { int nNum; MonkeyNo* pNext; MonkeyNo* pPre; }; MonkeyNo* pHeader = NULL; void AddList(int nD) { MonkeyNo* pNew = new MonkeyNo; pNew->pNext = pNew->pPre = NULL; pNew->nNum = nD; if(pHeader == NULL) { pHeader = pNew; }else { MonkeyNo* p = pHeader; while(p->pNext != NULL) { p = p->pNext; } p->pNext = pNew; pNew->pPre = p; } } void CreateMokeyLoop(int nM) { for(int nI = 1; nI <= nM; nI++) { AddList(nI); } MonkeyNo* p = pHeader; while(p->pNext != NULL) { p = p->pNext; } p->pNext = pHeader; pHeader->pPre = p; } void main() { int nN = 100; int nM = 2; CreateMokeyLoop(nN); MonkeyNo* p = pHeader; for(int nK = 0; nK < nN -1; nK++) { for(int nI = 0; nI < nM -1; nI++) { p = p->pNext; } printf("%d/n",p->nNum); p->pPre->pNext = p->pNext; p->pNext->pPre = p->pPre; MonkeyNo* q = p; p = p->pNext; delete q; } printf("%d/n",p->nNum); }