欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

C++中用兩個標準容器stack,實現(xiàn)一個隊列的方法詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

代碼如下所示:

復制代碼 代碼如下:

// StackToQueue.cpp : 定義控制臺應用程序的入口點。
//用兩個標準容器stack,實現(xiàn)一個隊列
#include "stdafx.h"
#include <iostream>
#include <stack>
using namespace std;
template <class T>
class StackToQueue
{
public:
 StackToQueue()
 {
  stack1;
  stack2;
 }
 void push(T e)
 {
  while (!stack2.empty())
  {
   T temp;
   temp = stack2.top();
   stack2.pop();
   stack1.push(temp);
  }
  stack2.push(e);
  while (!stack1.empty())
  {
   T temp;
   temp = stack1.top();
   stack1.pop();
   stack2.push(temp);
  }
 }

 void pop()
 {
   stack2.pop();
 }

 T front()
 {
  if (!empty())
  {
   return stack2.top();
  }
  else
  {
   return NULL;
  }
 }
 bool empty()
 {
  return stack2.empty();
 }
 size_t size()
 {
  return stack2.size();
 }
private:
 stack<T> stack1, stack2;
};
int _tmain(int argc, _TCHAR* argv[])
{
 StackToQueue<int> queue;
 int i(0);
 cout << "Enter several integer number,and press ctrl+z to the end." << endl;
 while (cin >> i)
 {
  queue.push(i);
 }
 cout << "The front element is: " << queue.front() << endl;
 cout << "The size now is: " << queue.size() << endl;
 if (!queue.empty())
 {
  cout << "Pop one element now." << endl;
  queue.pop();
 }
 cout << "The front element is: " << queue.front() << endl;
 cout << "The size now is: " << queue.size() << endl;
 return 0;
}

上一篇:如何用C++實現(xiàn)雙向循環(huán)鏈表

欄    目:C語言

下一篇:libxml教程(圖文詳解)

本文標題:C++中用兩個標準容器stack,實現(xiàn)一個隊列的方法詳解

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/4384.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有