c - Cannot enqueue array value -
i create queue
includes 2 dimensional array, size of every element of array 2. exception occurs when enqueue 2-size array in queue.
the following code:
#include "stdio.h" #define size 1000 typedef struct queue { int *data[2]; int front; int rear; }queue; void init(queue *q) { q->front=0; q->rear=0; } void enqueue(queue *q,int *value) { if(q->rear==size) return ; q->data[q->rear++]=value; } void main() { queue q[1]; init(q); int a[10][2]; for(int i=0;i<10;i++) { a[i][0]=i; a[i][1]=i*2+1; enqueue(q,a[i]); } }
*i create queue includes 2 dimensional array*
no create pointer array in onw dimensional int *data[2];
if want create quene include 2 demensional array , it int data[size][size_anoter]
however, didn't need 2 dimensional . in void enqueue(queue *q,int *value)
function , pass address a[i] data[i] . need big enough pointer array ;\
int * data[size];
besides , better if can define size
size
.
Comments
Post a Comment