队列用c++实现

来源:互联网 发布:守望先锋dva防御矩阵 编辑:程序博客网 时间:2024/05/14 07:24
由于经常用到队列,因此将队列的实现, 代码入下
typedef struct Node{    int data;    struct Node *next;}Node;typedef struct Queue{    Node *head, *tail;}Queue;void Initi(Queue &Q){    Q.head = (Node *)malloc(sizeof(Node));    Q.tail = Q.head;    Q.head->Next = NULL; }void EnQueue(Queue &Q, int d){    Node *node = (Node *)malloc(sizeof(Node));    node->data = d;    node->Next = NULL;    Q.rear->Next = node;    Q.rear = node;}bool IsEmpty(Queue Q){    Node *node = Q->head->Next;    if(node == NULL       return true;    return false;}


原创粉丝点击