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

      

  • 相关阅读:
    hashCode花式卖萌
    2017年的小总结
    多线程环境下的单例模式
    Servlet过滤器简单探索
    最长回文子序列(LPS)
    最短编辑距离问题
    赫夫曼编码
    DNA序列对齐问题
    同时寻找序列的最大最小值
    最长公共子序列(LCS)
  • 原文地址:https://www.cnblogs.com/52dxer/p/12286366.html
Copyright © 2011-2022 走看看