zoukankan      html  css  js  c++  java
  • 第十章-2-结构体练习

    /*
     * @Issue: 建立一个有头结点的单向链表,链表结点中数据通过键盘输入,输入到-1结束,头结点不放数据
     * @Author: 一届书生
     * @LastEditTime : 2020-02-09 10:27:10
     */
    #include<iostream>
    using namespace std;
    
    typedef struct node{
        int data;
        struct node *next;
    }Node,* Pnode;
    
    // 初始化
    Pnode craetlist(){
        Pnode p,q,ph;  //q:头结点 p:插入的结点 
        ph=new Node[sizeof(node)];
        q=ph;
        int a;
        cin>>a;
        while(a!=-1){
            p=new Node[sizeof(node)];
            p->data=a;
            q->next=p;
            q=p;
            cin>>a;
        }
        q->next=NULL;
        return (ph);
    }
    
    int main(){
        Pnode head;
        head=craetlist();
        Pnode p=head;
        while(p->next!=NULL){
            p=p->next;
            cout<<p->data<<endl;
        }
        return 0;
    }
    

      

    /*
     * @Issue: 建立一个双向链表,数据域info,前趋指针pre,后继指针next,并输出这个双向链表
     * @Author: 一届书生
     * @LastEditTime : 2020-02-09 10:35:43
     */
    
    #include<iostream>
    using namespace std;
    
    typedef struct node{
        int info;
        struct node *pre,*next;
    }Node,* Pnode;
    
    void printl(Pnode head){
        Pnode p;
        p=head->next;
        while(p!=NULL){
            cout<<p->info;
            p=p->next;
        }
    }
    
    int main(){
     
        return 0;
    }
    

      

  • 相关阅读:
    Java Class的field如果以小写t开头
    ACM集训日志——day1——15.7.8
    分金币 Uva 11300
    RMQ小结
    Poj 水题
    Codeforces Round #278 (Div. 2)
    poj 3685
    poj 3579
    vConsole
    js更换自定义鼠标指针图片
  • 原文地址:https://www.cnblogs.com/52dxer/p/12286366.html
Copyright © 2011-2022 走看看