#include <stdio.h> #include <stdlib.h> typedef struct _ListHead { struct _ListHead* pre; struct _ListHead* next; } ListHead; typedef struct _Data { ListHead list_head; int id; } Data; int main() { int i =0; const int maxData = 32; Data* head = NULL; Data* tail = NULL; Data* newData= NULL; Data* pData= NULL; for(i = 0; i < maxData; i++) { newData = (Data*)malloc(sizeof(Data)); if(!newData) { printf("no mem"); return -1; } memset(newData, 0, sizeof(Data)); newData->id = i; if(!head) { head = newData; tail = head; } else { tail->list_head.next = newData; newData->list_head.pre = tail; tail = newData; } } pData = head; if(!pData) { printf("null \n"); } while(pData) { printf("id:%d\n",pData->id); pData = pData->list_head.next; } return 0; }
在办公室一个小时都没写完,回来15分钟测完啥情况啊啊啊啊。