#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node* next;
} Node;
typedef struct mylist
{
Node* font;
Node* rear;
int size;
} List;
void init(List *l);
void destory(List *l);
void in(List *l,int num);
void out(List *l);
void display(List *l);
void create(Node *n,int num);
int main()
{
List l;
init(&l);
in(&l,3);
in(&l,4);
display(&l);
out(&l);
display(&l);
destory(&l);
return 0;
}
void init(List *l)
{
l->font = NULL;
l->rear = NULL;
l->size = 0;
}
void create(Node *n,int num)
{
n->data = num;
n->next = NULL;
}
void in(List *l,int num)
{
Node* nod = (Node*)malloc(sizeof(Node));
create(nod,num);
if(l->rear==NULL)
{
l->font = l->rear = nod;
}
else
{
l->rear->next = nod;
l->rear = l->rear->next;
}
l->size++;
}
void out(List *l)
{
Node* p;
if(l->size==0)
{
return ;
}
p = l->font;
l->font = l->font->next;
free(p);
l->size--;
}
void destory(List *l)
{
Node *p;
while(l->size!=0)
{
p = l->font;
l->font = l->font->next;
free(p);
l->size--;
}
}
void display(List *l)
{
if(l->size==0)
return ;
Node* p = l->font;
while(p!=l->rear)
{
printf("%d ",p->data);
p = p->next;
}
printf("%d\n",p->data);
}
C 队列
最新推荐文章于 2023-11-08 12:08:51 发布