zoukankan      html  css  js  c++  java
  • 转c之练手篇——"链表"

    // 链表Demo.cpp : 定义控制台应用程序的入口点。
    //

    #include
    "stdafx.h"
    #include
    <malloc.h>
    #include
    <stdlib.h>


    /*
    定义结构体
    */
    struct Node
    {
    int number;//数据域
    struct Node *pNext;//指针域
    };

    //声明函数
    struct Node * NodecreatList(void);
    void PutNodeList(struct Node *);

    int main(void)
    {
    struct Node *pHead;
    pHead
    =NodecreatList();//创建头结点单表链
    PutNodeList(pHead);
    return 0;
    }

    struct Node *NodecreatList()
    {
    int len;
    int val;
    struct Node *pHead;
    pHead
    =(struct Node*)malloc(sizeof(struct Node));
    if (NULL==pHead)
    {
    printf(
    "分配失败!程序终止.....");
    exit(
    -1);
    }

    struct Node * pTail=pHead;
    pTail
    ->pNext=NULL;

    printf(
    "请输入链表长度:\n");
    scanf(
    "%d",&len);
    for (int i=0;i<len;i++)
    {
    printf(
    "请输入第%d个数:",i+1);
    scanf(
    "%d",&val);
    struct Node *pNew=(struct Node *)malloc(sizeof(struct Node));
    if (NULL==pNew)
    {
    printf(
    "分配失败!程序终止.....");
    exit(
    -1);
    }
    pNew
    ->number=val;
    pTail
    ->pNext=pNew;
    pNew
    ->pNext=NULL;
    pTail
    =pNew;
    }
    return pHead;
    }
    void PutNodeList(struct Node *pHead)
    {
    struct Node *p=pHead->pNext;
    while(p!=NULL)
    {
    printf(
    "%d\n",p->number);
    p
    =p->pNext;
    }
    printf(
    "\n");
    return;
    }
  • 相关阅读:
    open-falcon之agent
    centos 7 部署 open-falcon 0.2.0
    高可用Redis服务架构分析与搭建
    python操作mongo脚本
    mongo查询日期格式数据
    离线下载pip包安装
    mongo同步到es
    mongo ttl索引
    kibana多台服务部署
    logstash过滤配置
  • 原文地址:https://www.cnblogs.com/Mr0909/p/1932066.html
Copyright © 2011-2022 走看看