小弟我这个链式队列的初始化工作,为什么会弹出"已停止运行"
我这个链式队列的初始化工作,为什么会弹出"已停止运行"?
------解决方案--------------------
//链式队列.cpp
#include <iostream>
using namespace std;
typedef struct node
{
char elem;
struct node *next;
}QNode;
typedef struct Lnode
{
QNode *front;//结构体指针
QNode *rear;
}LQueue;
//初始化队列
int Init_LQueue(LQueue *q)
{
q->front = new QNode;
q->rear = q->front;
q->front->next = NULL;
return 1;
}
int main()
{
LQueue *q = NULL;
Init_LQueue(q);
return 0;
}
------解决方案--------------------
LQueue *q = NULL;//q所指向的对象不存在 初始化函数中 q->front 也不存在
// 得先为q new一个对象才行 不是null
Init_LQueue(q);