我想用動態數組創建隊列,問題是當我測試int main()中的q.rear值(以後插入數據)時,它不再是-1。我做錯了哪一部分?排隊不正確地返回後方值?
這裏是一塊代碼:
#include <stdio.h>
#include <conio2.h>
#include <stdlib.h>
typedef struct{
int *data;
int front,rear,max;
}tqueue;
tqueue create(int size)
{
tqueue q;
q.data=(int *)malloc(size*sizeof(int));
q.front=0;
q.rear=-1;
q.max=size;
return q;
}
int main()
{
tqueue q;
int size=4;
create(size);
printf("\n%d",q.rear);
getch();
return 0;
}
我的錯,謝謝所有:) – mollyeah