zoukankan      html  css  js  c++  java
  • 【c语言】【每周一练】整数队列实现

    #include <stdio.h>
    struct node{
        int number;
        struct node * next;
    };
    void Init_list(struct node *root);
    void Push_list(struct node *p,struct node *root);void Pop_list(struct node *root);
    struct node* Get_list(struct node *root);
    void Print_list(struct node *root);
    
    
    int main(void){
        struct node head,a,b,*p;
        a.number=1;
        b.number=2;
        Init_list(&head);
        Push_list(&a,&head);
        Push_list(&b,&head);
        Print_list(&head);
        Pop_list(&head);
        p=Get_list(&head);
        Print_list(&head);
        printf("%d\n",p->number);
        Print_list(&head);
    }
    void Init_list(struct node *root){
        root->next=0;
        root->number=0;
    }
    void Push_list(struct node *p,struct node *root){
        struct node *head=root;
        while(head->next!= 0 ){head=head->next;}
        head->next=p;root->number++;
        p->next=0;
    }
    void Pop_list(struct node *root){
        
    if(root->next!=0)
    root->next=root->next->next;
    root->number--;
    }
    
    struct  node*  Get_list(struct node *root){
    return root->next;
    }
    
    void Print_list(struct node *root){
        struct node *head=root;
    printf("队列共有%d个元素\n",head->number);
    while(head->next!=0){
        head=head->next;    
    printf("%d\n",head->number);
    }
    }

    每周一练,day day up!


     

  • 相关阅读:
    C++STL——vector
    大数常用计算模板及例题
    在线算法&离线算法
    线段树——hdu1166敌兵布阵
    C++STL——堆栈
    C++STL——优先队列
    C++STL——队列
    图的建立——图的两种存储结构
    Manacher算法——最长回文子串
    HttpClient的几个实现类
  • 原文地址:https://www.cnblogs.com/huals/p/2501344.html
Copyright © 2011-2022 走看看