所以,我一直在敲我的頭大約三天,現在試圖找出如何讓這個工作。雙端隊列索引
我的任務是編寫一個雙端隊列。我對這部分沒有任何問題。
,我遇到了這個問題的事實是,給定一個指標時,我們必須有支架運營工作。所以,如果我把6放在後面,我想要[2] [2]回來,等等。但是,我不知道什麼方程會起作用。
我已經嘗試了一切,我GOOGLE了它,我已要求從誰已經在類人的幫助,這之前從未在課堂上這樣做沒有幫助那裏。沒有人討論過這個問題,每個人似乎都使用二維而不是搞亂一個索引。
我知道方程可能是很簡單,但在到期日是星期五的早晨,我還是要調試和運行單元測試。
這裏是它會在被使用的功能:
template<typename generic>
generic& Deque<generic>::operator[](unsigned int p)
{
return m_data[dq_index]->operator[](block_index);
}
類:
#include<stdexcept>
using std::out_of_range;
#include "block.h"
template<typename generic>
class Deque
{
public:
Deque();
Deque(unsigned int n);
Deque(Deque& d);
~Deque();
void push_front(generic x);
void pop_front();
void push_back(generic x);
void pop_back();
void clear();
Deque& operator=(const Deque& d);
generic& operator[](unsigned int p);
const generic& operator[](unsigned int p) const;
unsigned int size() const;
unsigned int block_size() const;
bool empty() const;
private:
Block<generic>** m_data;
unsigned int m_size;
unsigned int m_blocks;
unsigned int m_block_size;
};
分配:http://web.mst.edu/~buechler/datastructures/dequeclass.htm
你能否發佈`Deque`的類定義?你的問題意味着約束不屬於deque的基本定義的一部分,所以我們需要看到更多你正在使用的東西。 – zwol 2011-02-15 16:16:09
雙重結局與兩個維度無關,我不理解「我把6放到了我想得到[2] [2]回來」的部分。任何機會的任務確切的措辭? – Steve314 2011-02-15 16:16:37
[2] [2]就像塊2,索引2. – user618137 2011-02-15 16:21:03