c++ - Deque Implementation -


I have a question about the code found on the Internet that uses the deck to get the maximum of the element - < / P>

  #include & lt; Iostream & gt; #include & lt; Deque & gt; using namespace std; Zero Test (Ent Ar [], Int N) {std :: deque & lt; Int & gt; Qi (N); Int i; For (i = 0; i & lt; n; ++ i) {while ((qi.mpt)) and arr [i]> gt; = arr [qi back]) kupp_back (); // Remove from Qi.push_back (i); } Cout & lt; & Lt; Arrivals [Qi.front ()]; } // To test the driver program for work, int main () {int arr [] = {12, 1, 78, 90, 57, 89, 56}; Int n = sizeof (arr) / sizeof (ARE [0]); Test (ARM, N); Return 0; }   

My question is how is Qi.front () giving the correct index when I have not done any Qi.push_front ()?

But the following code will give me a 0

  zero test (ent ar), int n {std :: deque & lt; Int & gt; Qi (N); Int i; {Qi.push_back (i) for (i = 0; i & lt; n; ++ i); } Cout & lt; & Lt; Arrivals [Qi.front ()];    

Sorry, if I'm feeling stupid .. for new people ...

thanks < P>

stud :: deck & lt; Int & gt; Qi (N); n creates a deck with elements, all zeros push_back operations add further elements on the back, so the deck later contains the 2 * n element Qi.front () is the same Qi [0] .

All this is well documented, e.g. .

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -