Source1.cpp

Source1.cpp - tmp2 =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Double Queue Implementation File */ typdef struct _queuenode { struct _queuenode* link; QueueItemType data; }queuenode; typdef struct _BDQueueCDT { queuenode *link; queuenode *front1; queuenode *front2; queuenode *rear1; queuenode *rear2; int size1, size2; } Bdqueues; Bdqueues CreateBdqueues() { Bdqueues BDQ; BDQ = (Bdqueues)malloc(sizeof(BDQueue)); if(!BDQ) printf("There was a memory allocation error."); exit(1); queuenode newnode; newnode = (queuenode*)malloc(sizeof(queuenode)); if(!newnode) printf("There was a memory allocation error."); exit(1); BDQ->front1 = newnode; BDQ->rear1= newnode; BDQ->size1 = 0; queuenode newnode; newnode = (queuenode*)malloc(sizeof(queuenode)); if(!newnode) printf("There was a memory allocation error."); exit(1); Q->front2 = newnode; Q->rear2 = newnode; Q->size2 = 0; return BDQ; } void DestroyBdqueues(Bdqueues Q) { queuenode* tmp,tmp2; tmp = (Q->front1)->link;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tmp2 = (Q->front2)->link; while(tmp && tmp2) { tmp->link = (tmp->link)->link; tmp2->link = (tmp2->link)->link; free(tmp); free(tmp2); }; free(BDQ); } bool EmptyBdqueues(Bdqueues Q) { if ((Q->size1)== 0 && (Q->size2)== 0) return 0 ; else return 1; } int BdqueueseSize(Bdqeueue Q, int *Q1size, int *Q2size) { Q1size = Q->size1; Q2size = Q->size2; return ((Q->size1) = (Q->size2)); bool FullBdqueues(Bdqueues Q) { if ((Q->size1) + (Q->size2))= MAX_BDQ) return 1 else return 0; } bool EnqueueBdq(Bdqeueues Q, BdqueuesItemType *item) { if(FullBdqueues(Q) return 0; queuenode newnode; newnode = (queuenode*)malloc(sizeof(queuenode)); if(!newnode) printf("There was a memory allocation error") exit(1); if((Q->size1) < (Q->size2)) { (Q->rear1)->link = newnode; Q->rear1 = newnodel newnode->data = item; newnode->link = NULL...
View Full Document

This note was uploaded on 01/17/2012 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 2

Source1.cpp - tmp2 =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online