注册后可查看大图哦
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include<stdio.h>
#include<malloc.h>
typedef struct node
{
unsigned long int data;
node *next;
}node_t;
typedef struct queue
{
unsigned long int capacity;
node_t *head;
node_t *tial;
}queue_t;
queue *queue_create()
{
queue *q=(queue *)malloc(sizeof(queue_t));
if(q)
{
q->head=NULL;
q->tial=q->head;
}
return q;
}
queue *queue_puch(queue *queueopr,unsigned long int i)
{
node_t *nt=(node_t *)malloc(sizeof(queue_t));
nt->data=i;
nt->next=NULL;
if(queueopr->head==NULL)
{
queueopr->head=nt;
queueopr->tial=nt;
}else
{
queueopr->head->next=nt;
queueopr->head=nt;
}
}
void queue_print(queue *queueopr)
{
node_t *p=queueopr->tial;
do
{
printf("%lu >",p->data);
p=p->next;
}while(p);
printf("\r\n");
}
unsigned long int queue_pop(queue_t *queueopr)
{
unsigned long int b=queueopr->tial->data;
node_t *tem=queueopr->tial;
queueopr->tial=tem->next;
free(tem);
return b;
}
int main(int argc,const char *argv[])
{
queue *queueopr=queue_create();
for(int i=0;i<6;i++)
{
printf("input:%d\r\n",i);
queueopr=queue_puch(queueopr,i);
queue_print(queueopr);
}
for(int i=0;i<5;i++)
{
printf("pop:%lu\r\n",queue_pop(queueopr));
queue_print(queueopr);
}
return 0;
}
//欢迎讨论
|
|
Connecting & Messaging from Any.
|
|
|
共 0 个关于本帖的回复 最后回复于 2018-9-19 15:16