【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!


 

原文地址:https://www.cnblogs.com/huals/p/2501344.html