#pragma hdrstop
#include <iostream.h>
#include <conio.h>
//---------------------------------------------------------------------------
#pragma argsused
#define max 10
#define Nil -1
typedef struct{
int head;
int tail;
}Queue;
typedef struct{
int info;
int next;
}elmtQueue;
elmtQueue eq[max];
void createQueue(Queue *Q)
{
Q->head = Q->tail = Nil;
}
bool isFull (Queue Q)
{
return Q.tail == max;
}
bool isEmpty (Queue Q)
{
return Q.head == Q.tail == Nil;
//Q->head == Nill && Q->tail == Nil
}
void enQueue (Queue *Q, int x)
{
if (isEmpty(*Q))
{
Q->head = 0;
eq[Q->tail].info = x;
eq[Q->tail].next = Nil;
Q->tail++;
}
else
{
Q->tail++;
eq[Q->tail].info = x;
eq[Q->tail-1].next = eq[Q->tail].info;
}
}
void deQueue (Queue *Q)
{
Q->head++;
}
void display(Queue Q)
{
do{
cout<<eq[Q.head+1].info<<endl;
deQueue(&Q);
}while(Q.head!=Q.tail);
}
int main(int argc, char* argv[])
{
Queue Q;
int x;
createQueue (&Q);
enQueue (&Q,3);
enQueue (&Q,4);
enQueue (&Q,1);
display(Q);
getch();
return 0;
}
//---------------------------------------------------------------------------
No comments:
Post a Comment