• 【唉呀哎呀】今天考试这个题


    #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 
    ");
        }
        while(pData)
        {
            printf("id:%d
    ",pData->id);
            pData = pData->list_head.next;
        }
        return 0;
    }
    

     在办公室一个小时都没写完,回来15分钟测完啥情况啊啊啊啊。

  • 相关阅读:
    Windows Vs2010 + Qt5
    Java基础1
    关键字volatile
    内联函数
    Const详解2
    模板特化
    引用
    旧代码中的"enum hack"
    angularjs之ngoption
    angularjs之向下一个页面传参
  • 原文地址:https://www.cnblogs.com/yixiaoyang/p/3327362.html
Copyright © 2020-2023  润新知