Mn giúp em bài này với. Nó cứ báo hàng đợi rỗng. e k biết sai ở đâu
#include<iostream>
using namespace std;
struct node {
int data;
int prior;
struct node *next;
}*front;
void init(){
front =NULL;
}
void push(int x,int prior){
node *p,*s;
p->data=x;
p->prior=prior;
if(front ==NULL || prior > front->prior){
p->next=front;
front =p;
}
else {
s=front;
while(s->next!=NULL && s->next->prior<=prior){
s=s->next;
}
p->next=s->next;
s->next=p;
}
}
/*void pop(){
node *s=front;
if(front==NULL) cout<<" hang doi rong."<<endl;
else {
}
}
*/
void hienthi(){
node *s=front;
if(front ==NULL) cout<<" hang doi rong.";
else {
cout<<"\n Gia tri: "<<"\t "<<" Do uu tien"<<endl;
while(s!=NULL){
cout<<s->data<<"\t "<<s->prior;
s=s->next;
}
}
}
void nhap(int x,int prior){
while(1){
if(x!=0){
cout<<"nhap gia tri: "; cin>>x;
cout<<"nhap do uu tien: "; cin>>prior;
push(x,prior);
}
else break;
}
}
int main(){
int x,prior;
init();
nhap(x,prior);
hienthi();
}


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?