#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 *head;
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->head = h;
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)
{
}
请问这段代码哪里出了问题?编译的时候没有Bug,但是执行程序时无法输出。。。。。
懂了,Create_queue那里的判断语句中"=="写成了"="