• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            There is a will there is a way!

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              4 隨筆 :: 0 文章 :: 29 評論 :: 0 Trackbacks

            2006年4月15日 #

            ?? 在C++中有一些容器可以直接用的 如:queue stack priority_queue deque set map?
            ? 等。? 在這里我將說說vector;
            ?? vector<class T> vec; 這是定義一個空的向量, 方法有:size , push_back,pop_back; erase,empty,begin,end? 返回迭代器 等等, 還可以直接的下標操作 如:vec[i];還有就迭代器了? vector<class T>::iterartor it=vec.bengin();
            ? 還是看看例子吧:
            ?#include <iostream>
            ? #include <vector>
            ? using namespace std;
            int main()
            {
            ??? vector<int> vec;
            ??? int a;
            ??? while(cin>>a)
            ??? {
            ??????? vector.push_back(a);//vector是自動分配空間的
            ??? }
            ??? for(int i=0;i<vec.size();i++)
            ??? cout<<vec[i]<<endl;
            ??? vec.pop_back();
            ??? for(int i=0;i<vec.size();i++)
            ??? cout<<vec[i]<<endl;
            ??? return 1;
            }
            ? 當輸入是:1 2 3 4 5 時
            輸出是:
            1
            2
            3
            4
            5

            1
            2
            3
            4
            好了現(xiàn)在能簡單的用了吧!? 有問題在在網(wǎng)上留言吧!!

            posted @ 2006-04-15 14:35 王直元 閱讀(3423) | 評論 (7)編輯 收藏

            2006年4月14日 #


            priority_queue是很有用的的一個容器,你可以定義以什么為優(yōu)先.所以你可以定義方法,也就是一個函數(shù)類對象,C++中有一個<fanction>里面定義了一些方法 如:less<class T>??? 這是按值大的優(yōu)先 greater<class T>這是按值小的優(yōu)先,
            priority_queue<class T, class comp=less< class Y>> 默認的是以大為先, 方法有 push() , pop(), empty(), front().等等
            看看例子吧!

            #include?<iostream>
            #include?
            <queue>//有priority_queue
            using?namespace?std;
            int?main()
            {
            ????priority_queue
            <int>?q;
            ????
            int?a;
            ????
            while(cin>>a)
            ????
            {
            ????????q.push(a);
            ????}

            ????
            while(!q.empty())
            ????
            {
            ????????cout
            <<q.front()<<endl;
            ????????q.pop();
            ????}

            ????
            return?1;
            }


            輸入:3? 4 6 1 10 2 45 ctrl+z? ( ctrl+z是輸入結(jié)束標志)

            輸出:
            45
            10
            6
            4
            3
            2
            1
            posted @ 2006-04-14 00:21 王直元 閱讀(7905) | 評論 (13)編輯 收藏

            2006年4月13日 #

            文件  <stack>?? <queue>?? 使用時stack<class T>? st? queue<class T>? q
            stack?? 的使用方法有   push()的向容器頂部里插入元素, pop()是刪除容器頂部的元素, top()返回容器頂部的元素,size()返回容器的元素個數(shù),begin()是返回一個位于容器的第一個元素的迭代器,end()當然是最后了  empty()是檢查是否為空的方法 空時返回true 否則返回 false,
            queue 方法只有front()與 stack 不一樣 當然是返回對頭的元素,看看下面的例子吧.
            #include<iostream>
            #include
            <stack>
            #include
            <queue>
            using?namespace?std;
            int?main()
            {
            ????stack
            <int>?st;
            ????queue
            <int>?q;
            ????st.push(
            10);
            ????st.push(
            20);
            ????q.push(
            30);
            ????q.push(
            40);
            ????cout
            <<st.top()<<endl;
            ????st.pop();
            ????cout
            <<st.top()<<endl;
            ????cout
            <<q.front()<<endl;
            ????q.pop();
            ????cout
            <<q.front()<<endl;
            ????
            while(!st.empty())???//當然queue也能這樣用
            ????{
            ???????
            int?a=st.top();
            ???????cout
            <<a<<endl;
            ???????st.pop();
            ????}
            ?
            }


            output:

            20

            10

            30

            40

            10

            ?

            posted @ 2006-04-13 23:52 王直元 閱讀(6791) | 評論 (11)編輯 收藏

            2006年4月10日 #

                 摘要: 這里的迷宮是由0 1表示的 0表示墻, 1表示能通過 這里我用了const int row=7,column=13;你當然可以改動這個參數(shù). 運行后回把其中的一條路徑改成其它數(shù)字你會看到的, #include? < iostream > ...  閱讀全文
            posted @ 2006-04-10 23:21 王直元 閱讀(656) | 評論 (0)編輯 收藏

            僅列出標題  
            69SEX久久精品国产麻豆| 久久天堂电影网| 国内精品久久久久影院网站 | 久久久精品一区二区三区| 久久久久久久97| AV无码久久久久不卡网站下载| 中文字幕久久欲求不满| 久久精品中文字幕大胸| 久久无码av三级| 一级做a爰片久久毛片看看| 99国内精品久久久久久久| 亚洲国产成人久久综合碰| 狠狠色丁香婷综合久久| 一本久久免费视频| 国产精品久久久天天影视| 久久人人添人人爽添人人片牛牛| 999久久久免费精品国产| 2021国内精品久久久久久影院| 久久亚洲综合色一区二区三区| 精品人妻伦九区久久AAA片69| 伊色综合久久之综合久久| 91精品国产综合久久久久久| 亚洲国产成人精品91久久久 | 久久九九久精品国产免费直播| 久久综合久久自在自线精品自| 日本国产精品久久| 99久久婷婷国产综合亚洲| 久久久精品久久久久特色影视| 精品国产一区二区三区久久| 久久毛片一区二区| 久久免费小视频| 久久精品国产99国产电影网| 人妻精品久久久久中文字幕一冢本| 精品久久久久久久久免费影院 | 免费精品99久久国产综合精品| 97精品国产97久久久久久免费| 欧美久久综合九色综合| 久久99精品综合国产首页| 久久永久免费人妻精品下载| 久久久久亚洲av成人网人人软件| 中文字幕无码久久精品青草|