2021-03-09 11:45

# 关于链式队列的实现问题

#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

typedef int ElemType;
typedef struct LQNode{
ElemType elem;
LQNode *next;
}LQNode;
typedef struct Queue{
LQNode *tail;
}Queue;
Queue *Create_queue(ElemType A[], int size);
void Print_queue(Queue *Q);
void Enqueue(Queue *Q, ElemType e);
void Make_empty(Queue *Q);
bool Is_empty(Queue *Q);
ElemType Dequeue(Queue *Q);

int main()
{
//创建链式队列
ElemType A[] = {1,2,3,4,5,6,7,8,9};
int size = sizeof(A)/sizeof(ElemType);
Queue *Q = Create_queue(A, size);
Print_queue(Q);
cout << endl;

return 0;
}

Queue *Create_queue(ElemType A[], int size)
{
Queue  *Q = (Queue *)malloc(sizeof(Queue));
LQNode *h = (LQNode *)malloc(sizeof(LQNode));
LQNode *t = (LQNode *)malloc(sizeof(LQNode));
h->next = NULL;
for(int i=0; i<size; i++)
{
LQNode *p = (LQNode *)malloc(sizeof(LQNode));
p->elem = A[size-i-1];
p->next = h->next;
h->next = p;
if(i=0)    t->next = p;
}
Q->tail = t;
return Q;
}

void Print_queue(Queue *Q)
{
cout << "队头--";
LQNode *p = Q->head->next;
while(p != NULL)
{
cout << p->elem << "--";
p = p->next;
}
cout << "队尾" << endl;
}

void Enqueue(Queue *Q, ElemType e)
{

}

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答

#### 1条回答

• Dragon Ice 1月前

懂了，Create_queue那里的判断语句中"=="写成了"="

点赞 评论 复制链接分享