Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stl.h"
- // Returns a NEW stack of students containing only the students who live in
- // the given parameter home town. The order of the students in the new stack
- // should be preserved. That is students in the new stack should remain below
- // students who were higher up in the original stack. See tests for examples.
- stack<Student> homeTownStack(stack<Student> &students, string homeTown)
- {
- stack<Student> main = students;
- stack<Student> result;
- stack<Student> temporary;
- while(!main.empty()){
- if(main.top().getHomeTown() == homeTown){ // con top() buscamos el 1ero
- temporary.push(main.top()); // si es el que queremos se agrega a temp
- main.pop(); // pero en vez de ABC se agrega como CBA
- }
- else {
- main.pop();
- }
- }
- while(!temporary.empty()){ // para arreglar lo de CBA se pone en otro loop
- result.push(temporary.top()); // de CBA se vuelve ABC
- temporary.pop();
- }
- return result; // Dummy return. Please replace.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement