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;
    }
    

      

  • 相关阅读:
    剑指offer-二进制中1的个数
    [SHOI 2017] 分手是祝愿
    [SCOI 2010] 字符串
    [BZOJ 2653] middle
    [APIO 2015] 雅加达的摩天楼
    [NOI 2015] 品酒大会
    [SDOI 2015] 星际战争
    [Codeforces 715C] Digit Tree
    [TJOI 2018] 智力竞赛
    [CTSC 2018] 混合果汁
  • 原文地址:https://www.cnblogs.com/52dxer/p/12286366.html
Copyright © 2011-2022 走看看