#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分钟测完啥情况啊啊啊啊。

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2021-08-05
  • 2021-09-06
  • 2021-12-26
  • 2022-12-23
  • 2021-07-23
猜你喜欢
  • 2021-12-08
  • 2021-11-04
  • 2021-10-21
  • 2021-12-26
  • 2021-10-06
  • 2021-10-19
  • 2021-11-27
相关资源
相似解决方案