前幾天因爲測試需要寫了這段自動生成一個鏈表的代碼,貼上來興許以後用得着。 typedef struct card...{ card * previous; char index; card * next;}CARD;CARD * cpHead, * pCurrent, * pTmpCard;char i;//生成4個節點的鏈表,表頭用指針cpHead標記for(i = 0; i <= 3; i++)...{ pCurrent = (CARD *)malloc(sizeof(CARD)); pCurrent -> index = i + 65; pCurrent -> next = NULL; if(i == 0)...{ pCurrent -> previous = NULL; cpHead = pCurrent; }else...{ pTmpCard -> next = pCurrent; pCurrent -> previous = pTmpCard; } pTmpCard = pCurrent;}//打印pCurrent = cpHead;while(pCurrent != NULL)...{ printf("%c ", pCurrent -> index); pCurrent = pCurrent -> next;}