本文整理汇总了C++中Queue::DeQueue方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::DeQueue方法的具体用法?C++ Queue::DeQueue怎么用?C++ Queue::DeQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::DeQueue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
bool ok;
Queue queue;
queue.EnQueue(1);
queue.EnQueue(2);
queue.EnQueue(3);
// queue.ClearQueue();
// queue.IsEmpty();
while (!queue.IsEmpty())
{
cout << queue.DeQueue(ok) << endl;
}
queue.EnQueue(5);
queue.EnQueue(6);
while (!queue.IsEmpty())
{
cout << queue.DeQueue(ok) << endl;
}
return 0;
}
示例2: main
int main(){
Queue q;
q.EnQueue(5);
q.EnQueue(2);
q.EnQueue(6);
q.EnQueue(8);
cout << "Size: " << q.Size() << endl;
cout << q.DeQueue() << endl;
cout << q.DeQueue() << endl;
cout << q.DeQueue() << endl;
cout << q.DeQueue() << endl;
Stack s;
s.Push(8);
s.Push(6);
s.Push(2);
s.Push(5);
cout << s.Pop() << endl;
cout << s.Pop() << endl;
cout << s.Pop() << endl;
cout << s.Pop() << endl;
return 0;
}
示例3: main
int main(){
Queue q;
for (int i = 0; i < 10; i++)
q.EnQueue(i);
cout << q.DeQueue() << '\n';
cout << q.DeQueue() << '\n';
for (int i = 10; i < 20; i++){
q.EnQueue(i);
}
cout << q.DeQueue() << " ";
cout << q.DeQueue() << '\n';
}
示例4: Run
void BFS::Run(int** matrix, int size, int start)
{
int index = -1;
Queue* queue = new Queue();
SNode* node = new SNode();
node->value = start;
queue->EnQueue(node);
while(queue->GetLength() != 0)
{
node = queue->DeQueue();
index = node->value;
this->labels[index] = 1;
delete node;
for(int i=0; i<size; i++)
{
if(matrix[index][i] == 1 && this->labels[i] == 0)
{
node = new SNode();
node->value = i;
queue->EnQueue(node);
this->labels[i] = 1;
this->previous[i] = index;
}
}
node = NULL;
}
delete queue;
}
示例5: main
int main()
{
Queue Q;
for(int i = 0; i < 10; ++i)
{
int* p = new int(i);
Q.EnQueue(p);
cout << "Size = " << Q.Size() << endl;
}
for(QueueNode* node = Q.Head(); node != 0; node = node->next)
{
int* p =(int*)node->data;
cout << *p<< " ";
}
cout << endl;
while(Q.Empty() == false)
{
int* p = (int*)Q.DeQueue();
cout << *p << " ";
cout << "Size = " << Q.Size() << endl;
}
cout << endl;
return 0;
}
示例6: main
int main()
{
Queue a;
a.EnQueue(1);
a.EnQueue(2);
a.EnQueue(3);
int t = a.DeQueue();
int k = a.DeQueue();
cout << t << k << a.checkFront() << endl;//
system("pause");
return 0;
}
示例7: runtime_error
template <typename T> void test(Queue<T> testobj/*,bool type*/)
{
default_random_engine e;
/*
if(type)
goto inttype;
else
goto floattype;
inttype:
uniform_int_distribution<unsigned> u(0,9);
floattype:
uniform_real_distribution<double> u(0,9);
*/
uniform_real_distribution<double> u(0,9);
try{
cout<<"Now testing Queue Enqueue and DeQueue function:"<<endl;
char ch;
while(1)
{
try{
bool quit=false;
cout<<"EnQueue or DeQueue? press \"E or e\" for EnQueue, press \"D or d\" for DeQueue, press \"Q or q\" for quit: ";
cin>>ch;
switch(ch)
{
case 'e':
case 'E':
{
T temp=u(e);
testobj.EnQueue(temp);
cout<<"Generated random number: "<<temp<<" put it into the queue."<<endl;
cout<<"Now the queue is:"<<endl;
testobj.print();
break;
}
case 'D':
case 'd':
{
cout<<"Number: "<<testobj.DeQueue()<<" is DeQueued."<<endl;
cout<<"Now the queue is:"<<endl;
testobj.print();
break;
}
case 'q':
case 'Q':
{
quit=true;
break;
}
default:
throw runtime_error("Invalid input, try again!");
break;
}//end switch
if(quit)
break;
}//end inner try
catch(runtime_error err)
{
cerr<<err.what()<<endl;
}
}//end while
}
catch(overflow_error over)
{
cerr<<over.what()<<endl;
}
catch(underflow_error under)
{
cerr<<under.what()<<endl;
}
Queue<T> q2(testobj);
Queue<T> q3;
q3=q2;
cout<<"Now testing the copy assignement and assignment operator!"<<endl;
cout<<"The copy constructor assigned q2 from q, the q2 is:"<<endl;
q2.print();
cout<<"The assignment operator: q3=q2. the q3 is:"<<endl;
q3.print();
}
示例8: main
int main()
{
Queue<int> queue;
cout<<"******************************"<<endl;
cout<<"*selet an item "<<endl;
cout<<"*establish a quue,enter'1' " <<endl;
cout<<"*Enqueue,enter '2' "<<endl;
cout<<"*Dequeue enter '3' "<<endl;
cout<<"*quit,enter '0' "<<endl;
cout<<"******************************"<<endl;
int i;
do{
cout<<"ÇëÊäÈëÄãµÄÑ¡Ôñ£º";
cout<<"1---> establish¡¢2----Enqueue¡¢3----Dequeue¡¢4--->output¡¢0--->quit¡¢"<<endl;
cin>>i;
switch(i)
{
case 1:
cout<<"create a queue"<<endl;
cout<<"please enter the number of the queue"<<endl;
int j,s;
cin>>s;
for(j=0;j<s;j++){
cout<<"there is "<<s<<" numbers"<<endl;
cout<<"this is the "<<j+1<<"th number"<<endl;
int m;
cin>>m;
queue.EnQueue(m);
}
cout<<"OKey"<<endl;
break;
case 2:
cout<<"push members into queue:"<<endl;
int n,l;
cout<<"How many member you want to enter:"<<endl;
cin>>n;
for(i=0;i<n;i++){
cout<<"please enter the "<<i+1 <<"th member you want to push:"<<endl;
cin>>l;
queue.EnQueue(l);
}
cout<<"OK"<<endl;
break;
case 3:
cout<<"Dequeue"<<endl;
cout<<"How many member you want to pop"<<endl;
int m;
cin>>m;
for(i=0;i<m;i++){
queue.DeQueue();
}
cout<<"OK";
break;
case 4:
cout<<"the members in the queue"<<endl;
queue.Output();
break;
}
}while(i!=0);
return 0;
}
示例9: OnDraw
void CMFC_CreatBinaryTreeView::OnDraw(CDC* /*pDC*/)
{
CMFC_CreatBinaryTreeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CreatBinaryTreeDlg dlg; //创建对话框类对象
dlg.DoModal();
//CString转换为wchar_t*
wchar_t *VLR = dlg.PreBinTree.GetBuffer();
dlg.PreBinTree.ReleaseBuffer();
wchar_t *LVR = dlg.MidBinTree.GetBuffer();
dlg.MidBinTree.ReleaseBuffer();
int N = dlg.PreBinTree.GetLength(); //前序序列的长度,二叉树结点个数
int len = dlg.MidBinTree.GetLength(); //中序序列的长度
if (N != len)
{
INT_PTR Respon;
Respon = MessageBox(_T("前序和中序序列输入错误,退出!"), _T("错误提示"), MB_OK | MB_ICONSTOP);
return;
}
//将对话框中的输入数据传入创建二叉树的模板类的构造函数中构造二叉树
CBinaryTree<wchar_t> BinTree(VLR, LVR, N);
BinTreeNode<wchar_t> *Root = BinTree.GetRoot(); //获取二叉树的根结点
int depth = BinTree.Depth(Root); //二叉树的深度
Queue<BinTreeNode<wchar_t>*, int, int> Q; //添加队列,用来存储二叉树的结点,以及结点所显示位置的圆的圆心坐标
//获取菜单文本的坐标
CRect Re;
this->GetWindowRect(Re);
auto w = Re.Width();
auto h = Re.Height();
CClientDC Dc(this);
//结点的坐标分布
int Height = 1; //结点的高度每增加一层点,高度就加一
int HeightLeft; //左孩子结点的高度
int HeightRight; //右孩子结点的高度
int R = h / (4 * (depth + 1)); //圆的半径
int Molecule = 1; //圆心坐标的分子
int Denominator; //圆心坐标的分母
int X0, Y0; //包装结点数据的圆的圆心坐标
int XA, YA, XD, YD; //圆外接正方形的左上角和右下角端点的坐标
int XE, YE, XF, YF; //连接两个圆的线段的端点坐标,点E在点F的上方
Q.EnQueue(Root, Molecule, Height);
while (!Q.IsEmpty())
{
//将当前结点的相关数据弹出
Q.DeQueue(Root, Molecule, Height);
//圆心坐标
Denominator = (int)pow(2, Height);
X0 = w*Molecule / Denominator; //圆心横坐标
Y0 = h*Height / (depth + 1); //圆心纵坐标
//正方形的两端点的坐标
XA = X0 - R; //正方形左上角端点坐标
YA = Y0 - R;
XD = X0 + R; //正方形右下角端点坐标
YD = Y0 + R;
//画圆
Dc.Ellipse(XA, YA, XD, YD);
//在圆心显示二叉树的根结点数据
CString da;
da += Root->data;
Dc.SetTextColor(RGB(255, 0, 0)); //设置输出文本颜色为红色
Dc.TextOutW(X0, Y0, da);
if (Root->LeftChild)
{
//如果有左孩子,就画左线段
//线段的上端点坐标
XE = (int)(X0 - R / sqrt(2)); //XO为当前结点的圆心横坐标
YE = (int)(Y0 + R / sqrt(2)); //YO为当前结点的圆心纵坐标
HeightLeft = Height + 1; //高度加一
Molecule = 2 * Molecule - 1; //左为减,左子女的圆心横坐标的分子
//线段的下端点坐标
XF = w*Molecule / (2 * Denominator);
YF = h*HeightLeft / (depth + 1) -R;
//画左线段
Dc.MoveTo(CPoint(XE, YE));
Dc.LineTo(CPoint(XF, YF));
//将访问左子女所需要的数据压入队列
Q.EnQueue(Root->LeftChild, Molecule, HeightLeft);
Molecule = (Molecule + 1) / 2; //将跟结点圆心的分子还原
}
if (Root->RightChild)
{
//如果有右孩子,就画右线段
//线段的上端点坐标
XE = (int)(X0 + R / sqrt(2)); //XO为当前结点的圆心横坐标
//.........这里部分代码省略.........