Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.8 kB
3
Indexable
Never
    template <typename T>
	std::string cyclic_double_queue<T>::print_status() const
	{
		//TODO: Remove following line and add your implementation here.
		std::string result;
        if(m_size == 0){
            for(size_t i = 0; i<m_capacity; ++i){
                result += "[-]";
            }
        }
        else if(m_size == m_capacity){
            for(size_t i =0; i<m_capacity; i++){
                result += "[+]";
            }
        }
        else {
            if(m_backIndex < m_frontIndex){
                for (size_t i = 0; i < m_capacity; ++i) { // 2
                    // if ( i < m_backIndex && m_backIndex < m_frontIndex) {
                    //     // queue is B - F
                    //     result += "[+]";
                    // }
                    // else if (i >= m_frontIndex && i < m_backIndex && m_backIndex < m_capacity) {
                    //     // queue is F - B
                    //  result += "[+]";   
                    // }
                    // else {
                    // 	result += "[-]";
                    // }
                    if(i < m_backIndex && i < m_frontIndex){
                        result += "[+]";
                    }
                    else if(i < m_frontIndex){
                        result += "[-]";
                    }
                    else{
                        result += "[+]";
                    }
                }
            }
            else{
                for(size_t i =0; i<m_capacity; i++){
                    if(i >= m_frontIndex && i < m_backIndex){
                        result += "[+]";
                    }
                    else{
                        result += "[-]";
                    }
                }
            }
        }
        return result;
    }
Leave a Comment