该程序没有提供所需的输出.错误的FIFO实现?

pro*_*eve -2 c++ queue fifo visual-c++ data-structures

这是一个使用的FIFO程序linked list.该程序没有提供所需的输出,但会生成一个长循环,该循环在某个时间后停止并且有一条消息表明程序已停止工作.问题是什么 ?

#include <iostream>
using namespace std;

struct node {
      int data;
      struct node* previous; // This pointer keeps track of the address of the previous node
};

struct queue {
      node* first;
      node* last;
};

node* dataNode_P_A; 

bool loop = true;

struct node* enterData();
struct node* enter_N_Data();
void displayQueue();

int main() {
    struct node* dataNode= enterData();

    while( loop ) {
        cout << "Want to enqueue ? Press y/n : ";
        char ans;
        cin >> ans;
        if( ans == 'y' )  {
          struct node* dataNode_N = enter_N_Data();
        } else {
          break;
        }
    }

  displayQueue();
}

 struct node* enterData() {
    cout << "Enter the number : ";
    dataNode_P_A = new node;  // Now dataNode points to a chunk allocated to node
    cin >> dataNode_P_A->data;
    dataNode_P_A->previous = NULL; // this is set to NULL because no one follows till now   
    queue* q = new queue; 
    q->first = dataNode_P_A; // this pointer points to the first element
    return dataNode_P_A;
}

struct node* enter_N_Data() {
    cout << endl << "Enter the number : ";
    node* dataNode = new node;
    cin >> dataNode->data;
    dataNode->previous = dataNode_P_A; 
    queue* q = new queue;
    q->last = dataNode; // this pointer points to the last element
    return dataNode;
}

void displayQueue() {
    while( dataNode_P_A != NULL ) {
        cout << dataNode_P_A->data  << endl;
        dataNode_P_A++;
    }
}
Run Code Online (Sandbox Code Playgroud)

Bet*_*eta 6

你正在构建queues然后放弃它们.

您无法更新dataNode_P_A,因此您不会像流苏那样构建列表.

dataNode_P_A++当你明确不知道它意味着什么时,你会调用.

你编写了一段冗长而复杂的代码而没有对它进行测试.

你应该重新开始,一步一步走.