You are viewing a single comment's thread. Return to all comments →
hey i used queues too...but i am getting a wrong answer for test cases in which n= 100000. where is this code going wrong. please help!
void queue :: circle() { node *now= front; int Pleft= 0, c= 0, index= 0; node *temp= now, *ptr= now; while(temp->next != now) { Pleft+= temp->petrol; //cout<<"pleft: "<<Pleft<<" distance: "<<temp->dist<<endl; if(Pleft < temp->dist) { temp= ptr->next; now= temp; ptr= temp; Pleft= 0; c= 0; } else { c++; if(c == 1) { ptr= temp; index= temp->petrol; } Pleft-= temp->dist; // cout<<"in else pleft: "<<Pleft<<endl; temp= temp->next; } } int flag= 0; while(front->next != front) { if(index == front->petrol) { cout<<flag<<endl; break; } flag++; front= front->next; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Truck Tour
You are viewing a single comment's thread. Return to all comments →
hey i used queues too...but i am getting a wrong answer for test cases in which n= 100000. where is this code going wrong. please help!