• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              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
            好了現在能簡單的用了吧!? 有問題在在網上留言吧!!

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

            2006年4月14日 #


            priority_queue是很有用的的一個容器,你可以定義以什么為優先.所以你可以定義方法,也就是一個函數類對象,C++中有一個<fanction>里面定義了一些方法 如:less<class T>??? 這是按值大的優先 greater<class T>這是按值小的優先,
            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是輸入結束標志)

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

            2006年4月13日 #

            文件  <stack>?? <queue>?? 使用時stack<class T>? st? queue<class T>? q
            stack?? 的使用方法有   push()的向容器頂部里插入元素, pop()是刪除容器頂部的元素, top()返回容器頂部的元素,size()返回容器的元素個數,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 王直元 閱讀(6761) | 評論 (11)編輯 收藏

            2006年4月10日 #

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

            僅列出標題  
            AV狠狠色丁香婷婷综合久久| 人人狠狠综合久久亚洲婷婷| 一本综合久久国产二区| 性欧美大战久久久久久久| 亚洲国产综合久久天堂| 久久久久久久波多野结衣高潮| 久久久久亚洲AV无码永不| 精品99久久aaa一级毛片| 天堂无码久久综合东京热| 国产成人久久精品一区二区三区 | 亚洲国产精品久久久久婷婷老年| 精品久久国产一区二区三区香蕉| 国产69精品久久久久观看软件| 精品久久久久久久无码| 无夜精品久久久久久| 青青草原综合久久大伊人精品| 久久人与动人物a级毛片| 7国产欧美日韩综合天堂中文久久久久 | 99国产精品久久| 久久大香萑太香蕉av| 国产福利电影一区二区三区久久久久成人精品综合 | 久久99毛片免费观看不卡| 亚洲欧美成人久久综合中文网| 久久99精品久久久久婷婷| 久久天天躁狠狠躁夜夜2020一| 久久久久九九精品影院| 久久国产欧美日韩精品| 久久人人添人人爽添人人片牛牛 | 亚洲国产成人久久精品影视 | 国产亚州精品女人久久久久久| 精品久久久无码人妻中文字幕豆芽| 久久大香萑太香蕉av| 国产精品久久久久免费a∨| 久久精品18| 无码8090精品久久一区| 精品久久久久一区二区三区| 国产高潮国产高潮久久久91| 国产高清美女一级a毛片久久w | 久久不见久久见免费视频7| 久久综合亚洲欧美成人| 日韩人妻无码精品久久久不卡|