(+84) 236.3827111 ex. 402

Cài Đặt Queue


template struct Node{
T data;
Node *next;
};
template struct Queue{// front-> rear->null
Node *rear; // cuoi
Node *front; //dau
void creatQ(){
rear =NULL;
front=NULL;
}
bool isEmpty(){
if(rear==NULL) return true;
return false;
}
void push(T x){// them vao cuoi,
Node *l=new Node();
l->next=NULL;
l->data=x;
if(rear == NULL) front = l;
else rear->next=l;
rear=l;
}
T Front(){
// if(front!=null)
return front->data;
// return NULL;
}
void pop(){
if(front!=NULL){
Node *p = front;
front =front->next;
delete p;
}
}
};