• <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 王直元 閱讀(3416) | 評論 (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 王直元 閱讀(7895) | 評論 (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 王直元 閱讀(6760) | 評論 (11)編輯 收藏

            2006年4月10日 #

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

            僅列出標題  
            99久久精品这里只有精品| 久久精品日日躁夜夜躁欧美| 久久亚洲AV成人无码国产| 97久久精品无码一区二区天美| 婷婷国产天堂久久综合五月| 97香蕉久久夜色精品国产| 久久无码国产专区精品| 99久久精品国产高清一区二区 | 青青热久久国产久精品 | 久久国产精品国语对白| 亚洲人成网亚洲欧洲无码久久| 国产精品久久一区二区三区| 性做久久久久久久久老女人| 狠狠色丁香久久婷婷综合五月| 伊人久久大香线蕉无码麻豆| 国产精品久久久天天影视| 成人综合久久精品色婷婷| 亚洲一本综合久久| 亚洲AV无码久久精品成人| 久久精品一区二区影院| 久久综合九色综合欧美狠狠| 亚洲精品无码久久久久sm| 久久亚洲AV无码西西人体| 久久99精品久久只有精品| 精品久久人人爽天天玩人人妻| 精品久久久久久无码中文野结衣| 久久水蜜桃亚洲av无码精品麻豆| 久久久久亚洲国产| 亚洲伊人久久成综合人影院 | 国产三级久久久精品麻豆三级| 国产精品久久久久a影院| 久久久久久亚洲精品无码| 色综合久久久久| 国产精品欧美久久久久无广告 | 伊人久久精品无码av一区| 伊人精品久久久久7777| 久久久久久国产精品无码下载| 一本久久久久久久| 久久国产热这里只有精品| 久久一本综合| 国产69精品久久久久9999APGF|