Re: [問題] dequeue的小問題

看板C_and_CPP作者 (阿美)時間14年前 (2010/05/08 17:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《pilistar0222 (louis)》之銘言: : ( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 ) : ( 未必需要依照此格式,文章條理清楚即可 ) : 遇到的問題: (題意請描述清楚) : 我寫的一個 enqueue 可是我不知道哪裡有錯!! : 希望得到的正確結果: : 程式跑出來的錯誤結果: : compile會過,但是會錯 : 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) : Dev-C++ : 有問題的code: (請善用置底文標色功能) : #include <stdio.h> : #include <stdlib.h> : struct Node{ : int data; : struct Node *next; : }; : typedef struct Node Node; : struct Queue{ : int size; : Node *head,*tail; : }; : typedef struct Queue Queue; : void enqueue(Queue *a,int); : int dequeue(Queue *); : int is_empty(Queue *); : int main(){ : ... : ...(中間部分省略) : ... : return 0; : } int dequeue(Queue *q){ Node *x; int val; if(q->size ==0) //空的queue return 0; x = q->head; val = q->head->data; if(q->size==1){ //只剩一個data q->tail=NULL; q->head=NULL; } else{ q->head = q->head->next; } q->size--; delete x; return val; //回傳值 } : 補充說明: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.8.114
文章代碼(AID): #1BvJCPgH (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1BvJCPgH (C_and_CPP)