0

構造体に関する他の問題を解決した後、プッシュは意図したとおりに機能しますが、ポップが間違ったアドレスを返し、その理由がわかりません -

QNode* const Q_Pop(Q* const pointerQ){

   ...       // empty check

   QNode* tempNode = pointerQ->front.next;

   pointerQ->front.next = (tempNode->next);
   tempNode->next->prev = &(pointerQ->front);

   return tempNode;
}

スタックの実際の削除と再リンクに関する私のロジックは正しいと確信していますが、ポインターの使用とそれらを返すことはめちゃくちゃです。

構造体 -

struct QueueNode {

   struct QueueNode *prev;     /* Previous list element. */
   struct QueueNode *next;     /* Next list element.    */
};

typedef struct QueueNode QNode;

struct Queue {
   QNode front;    // sentinel node at the front of the queue
   QNode rear;     // sentinel node at the tail of the queue
};

typedef struct Queue Q;

助けてくれてありがとう!

4

1 に答える 1