zoukankan      html  css  js  c++  java
  • LinkList

    #define LOCAL
    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    using namespace std;
    typedef int ElemType;
    typedef struct Node
    {
        ElemType data;
        struct Node *next;
    }Node,*LinkList;
    void DisplayList(LinkList L)
    {
        Node *p=L->next;
        cout<<"display:"<<L->data<<endl;
        while(p!=NULL)
        {
            cout<<p->data<<",";
            p=p->next;
        }
    }
    void InitList(LinkList *L)
    {
        (*L)=(LinkList)malloc(sizeof(Node));
        (*L)->next=NULL;
    }
    void CreateHeadList(LinkList L)
    {
        Node *p;
        ElemType a;
        L->data=0;
        while(cin>>a)
        {
            p=(Node *)malloc(sizeof(Node));
            p->data=a;
            p->next=L->next;
            L->next=p;
        }
    }
    void CreateHeadList1(LinkList L)
    {
        Node *p,*h;
        h=L->next;
        ElemType a;
        L->data=0;
        while(cin>>a)
        {
            p=(Node *)malloc(sizeof(Node));
            p->data=a;
            L->data++;
            p->next=h;
            h=p;
        }
        L->next=h;//注意此处一定要有,就是把h连接到L->next后 
    }
    void CreateTailList(LinkList L)
    {
        Node *p,*r;
        ElemType a;
        r=L;
        L->data=0;
        while(cin>>a)
        {
            p=(Node *)malloc(sizeof(Node));
            p->data=a;
            p->next=NULL;
            L->data++;
            r->next=p;
            r=p;
        }
        r->next=NULL;    
    }
    void UseT(LinkList &L)
    {
        //Node *p=(*L).next;
        Node *p=L->next;
        cout<<endl<<"&L:"<<endl;
        while(p!=NULL)
        {
            cout<<p->data<<",";
            p=p->next;
        }
        cout<<endl;
    }
    int main()
    {
    #ifdef LOCAL
        freopen("2.in","r",stdin);
        freopen("2.out","w",stdout);
    #endif    
        LinkList Head;
        InitList(&Head);
        //CreateHeadList1(Head);
        CreateTailList(Head);
        DisplayList(Head);
        UseT(Head);//放进去Head 然后&把Head打包
        return 0;
    }
    display:10
    1,2,3,4,5,6,7,8,9,10,
    &L:
    1,2,3,4,5,6,7,8,9,10,
  • 相关阅读:
    在Xsheel Linux上安装nodejs和npm
    判断js中的数据类型的几种方法
    Sequelize 中文API文档-1. 快速入门、Sequelize类
    php中 ob_start()有什么作用
    PHP错误类型及屏蔽方法
    ajax对象的获取及其常用属性
    linux工作笔记
    Redis和Memcached的区别
    MySQL架构
    Http协议三次握手过程
  • 原文地址:https://www.cnblogs.com/jianfengyun/p/4011357.html
Copyright © 2011-2022 走看看