zoukankan      html  css  js  c++  java
  • 单链表(带头节点)

    /////////////////////////////////定义节点结构体

    struct node
    {
    int data;
    struct node *pnext;
    };

    ////////////////////////////////////main函数

    int main()
    {

    struct node *pHeader = creatList(0);

    /*insert_tail(creatList(1),pHeader);
    insert_tail(creatList(2),pHeader);
    insert_tail(creatList(3),pHeader);*/

    insert_head(creatList(1),pHeader);
    insert_head(creatList(2),pHeader);
    //creatList(1);
    printf("p1的data为:%d 总的节点数为:%d ",pHeader->pnext->data,pHeader->data);
    printf("p2的data为:%d 总的节点数为:%d ",pHeader->pnext->pnext->data,pHeader->data);
    //printf("p3的data为:%d 总的节点数为:%d ",pHeader->pnext->pnext->pnext->data,pHeader->data);
    //creatList(2);
    system("pause");
    return 0;
    }

    //////////////////////////////////创建新节点

    struct node * creatList(int data)
    {
    struct node *p ;
    p =(struct node *)malloc(sizeof(struct node));
    //忘记判断了
    if(p == NULL)
    {
    printf("创建节点指针失败");
    return NULL;
    }
    //忘记清0了
    memset(p,0,sizeof(struct node));
    p->data = data;
    p->pnext = NULL;
    return p;
    }

    ///////////////////////////////尾插法

    void insert_tail(struct node * newNode, struct node *pHeader)
    {
    struct node * p = pHeader;
    int length = 0;
    while(p->pnext!= NULL)
    {
    p = p->pnext;
    length++;
    }
    pHeader->data = length+1;
    p->pnext = newNode;

    }

    //////////////////////////////////////头插法

    void insert_head(struct node *newNode,struct node *pheader)
    {
    struct node * p = newNode;
    p->pnext = pheader->pnext;
    pheader->pnext = p;

    pheader->data +=1;
    }

  • 相关阅读:
    nginx构建https
    安装mysql的遇到的问题
    docker mysql 2059
    centos7 安装chrome
    谷歌浏览器启动参数
    php-webdriver:PHP控制浏览器动作, php web驱动, PHP实现自动化, php webdriver 教程, A php client for webdriver.
    nginx转发
    nginx变量与实列
    mysql 语句
    frp 内网穿透配置
  • 原文地址:https://www.cnblogs.com/tiange-137/p/11962938.html
Copyright © 2011-2022 走看看