2000 Mar 26
Cho O. Train is writing a program to simulate ordering of railroad cars. He needs you to write a data structure representing the order of the cars in the train that he can use for his program. Each train car will be represented with a char.
The operations he needs to support include:
push_front('z') | add the character to the front/left side of the train |
push_back('z') | add the character to the back/right side of the train |
pop_front() | remove the character at the front/left side |
pop_back() | remove the character at the back/right side |
front() | return the character at the front/left side |
back() | return the character at the back/right side |
dq[3] | return the character in car number 3 in deque dq |
empty() | return true if and only if the deque has no elements |
output operator | prints the characters in the deque |
Popping does not return any characters. front, back, and dq[3] will work only if the desired characters exist. They should support both returning the specified characters and changing their values.