The following is an implementation of my queue, which has the functions of a queue and a queue from a queue. For some reason, it crashes without prompting (where it crashes), since the code works on android. I suspect my queue code. If you guys know what is wrong with my code, please give me an idea.
Thanks for any help.
Here is my C code:
int qLast = 0;
typedef struct phoneSt PhoneStructure;
typedef struct{
PhoneStructure Phone;
struct phoneQ *next;
}phoneQ;
phoneQ *headElement = NULL;
phoneQ *tailElement = NULL;
void enqueue_Phone(PhoneStructure Frame)
{
phoneQ *newnode;
newnode=(phoneQ*)av_malloc(sizeof(phoneQ));
newnode->next=NULL;
newnode->Phone=Frame;
qLast++;
if(headElement==NULL && tailElement==NULL)
{
headElement=newnode;
tailElement=newnode;
}
else
{
tailElement->next=newnode;
tailElement=newnode;
}
__android_log_print(ANDROID_LOG_DEBUG, "myphone.c", "Queue is having %d element", qLast);
}
PhoneStructure dequeue_Phone()
{
phoneQ *delnode;
PhoneStructure Frame;
__android_log_write(ANDROID_LOG_DEBUG, "myplayer.c", "In dequeue_Phone");
if(headElement==NULL && tailElement==NULL){
__android_log_write(ANDROID_LOG_ERROR, "myphone.c", "Queue is empty to delete any element");
}
else
{
__android_log_write(ANDROID_LOG_DEBUG, "myphone.c", "In dequeue queue is not empty");
delnode=headElement;
headElement=headElement->next;
Frame = delnode->Phone;
av_free(delnode);
qLast--;
}
__android_log_print(ANDROID_LOG_DEBUG, "myphone.c", "In dequeue_Phone returning remaining %d",qLast);
return Frame;
}
source
share