结构体队列的简单创建方法
typedef struct Queue
{
Node* head;
Node* tail;
int size;
}Queue;
结构体Queue 含首尾两个指针与size大小量
void enQueue(Queue* que, int x,int y) //入队
{
Node* p;
p = (Node*)malloc(sizeof(Node));
p->x = x;
p->y = y;
p->next = NULL;
if(que->size==0)
{
que->head = p;
que->tail = p;
}
else
{
que->tail->next=p;
que->tail = p;
}
que->size+=1;
}
void deQueue(Queue* que, int x , int y) //出队
{
target = que.head;
y = target->y;
step = target->step;
que.head = target->next;
que.size -= 1;
}
这里也可以在出队函数里malloc一个结构体存储出队的元素进行输出
此博客为个人学习笔记,转载请说明出处