• <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>

            T9的空間

            You will never walk alone!

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              69 隨筆 :: 0 文章 :: 28 評(píng)論 :: 0 Trackbacks

            #

             1/*
             2  Name: build priority_queue
             3  Copyright: 
             4  Author: Torres
             5  Date: 29-08-08 10:48
             6  Description: 建立優(yōu)先隊(duì)列的方法 
             7*/

             8#include<iostream>
             9#include<vector>
            10#include<queue>
            11using namespace std;
            12template<class T>void print(T &a){while(!a.empty()){cout<<a.top()<<" ";a.pop();}cout<<endl;}
            13typedef struct node{
            14    int x,y;
            15    bool operator<(const node &a)const{
            16        return x>a.x||(x==a.x&&y>a.y);
            17    }

            18}
            node;
            19
            20/*typedef struct data{
            21    double x,y;
            22    bool cmp(data &a){
            23        return x>a.x||(x==a.x&&y>a.y);
            24    }
            25}data;*/

            26priority_queue<int,vector<int>,less<int> >LessIntq;//雖然是less但是是最大優(yōu)先
            27priority_queue<int>SysIntq;//默認(rèn)是less
            28priority_queue<int,vector<int>,greater<int> >GreatIntq;
            29priority_queue<node>Nodeq;
            30//priority_queue<data,vector<data>,cmp>Cmpdata;
            31
            32
            33int main()
            34{
            35    int i,temp;
            36    for(i=1;i<=5;i++){
            37        scanf("%d",&temp);
            38        LessIntq.push(temp);
            39        SysIntq.push(temp);
            40        GreatIntq.push(temp);
            41    }

            42    cout<<"LessIntq::";
            43    print(LessIntq);
            44    cout<<"SysIntq::";
            45    print(SysIntq);
            46    cout<<"GreatIntq::";
            47    print(GreatIntq);
            48    cout<<"******************"<<endl;
            49
            50    node ntemp;
            51    for(i=1;i<=5;i++){
            52        scanf("%d%d",&ntemp.x,&ntemp.y);
            53        Nodeq.push(ntemp);
            54    }

            55    cout<<"Nodeq::"<<endl;
            56    for(i=0;i<5;i++){
            57        cout<<Nodeq.top().x<<"::"<<Nodeq.top().y<<endl;
            58        Nodeq.pop();
            59    }

            60
            61/*    data dtemp;
            62    for(i=1;i<=5;i++){
            63        scanf("%lf%lf",&dtemp.x,&dtemp.y);
            64        Cmpdata.push(dtemp);
            65    }
            66    cout<<"Cmpdata::";
            67    for(i=0;i<5;i++){
            68        cout<<Cmpdata.top().x<<"::"<<Cmpdata.top().y<<endl;
            69        Cmpdata.pop();
            70    }*/

            71    return 0;
            72}

            73/****************************************
            742 5 1 3 7
            75LessIntq::7 5 3 2 1
            76SysIntq::7 5 3 2 1
            77GreatIntq::1 2 3 5 7
            78******************
            791 2
            805 6
            812 3
            822 10
            837 7
            84Nodeq::
            851::2
            862::3
            872::10
            885::6
            897::7
            90Press any key to continue
            91*************************************/
            posted @ 2008-08-29 11:31 Torres 閱讀(335) | 評(píng)論 (0)編輯 收藏

                 摘要: 在模板參數(shù),傳遞類名,在 ( 離散 ) 函數(shù)參數(shù)中,使用函數(shù)名 ( myStruct(); 或 myFunc ) 內(nèi)置 <functional> : greater <T>, less<T>, greater_equal<T>, less_equal<T>, equal_to<T>, not_equal_to<T&g...  閱讀全文
            posted @ 2008-08-28 21:31 Torres 閱讀(215) | 評(píng)論 (0)編輯 收藏

                 摘要:   1#include<iostream>  2#include<string>  3#include<algorithm>  4using namespace std;  5int main()  6{ ...  閱讀全文
            posted @ 2008-08-19 17:16 Torres 閱讀(270) | 評(píng)論 (0)編輯 收藏

            C++ Queues

            The C++ Queue is a container adapter that gives the programmer a FIFO (first-in, first-out) data structure.

            Display all entries for C++ Queues on one page, or view entries individually:

            Queue constructor construct a new queue
            back returns a reference to last element of a queue
            empty true if the queue has no elements
            front returns a reference to the first element of a queue
            pop removes the first element of a queue
            push adds an element to the end of the queue
            size returns the number of items in the queue
             1#include<iostream>
             2#include<queue>
             3#include<algorithm>
             4using namespace std;
             5int main()
             6{
             7    //隊(duì)列,first_in ,first_out,不提供迭代器,不提供走訪功能
             8    int i;
             9    queue<int>q;
            10    for(i=0;i<5;i++)q.push(i);
            11    while(q.size()){
            12        cout<<q.front();
            13        q.pop();
            14    }

            15    return 0;
            16}

            17
            posted @ 2008-08-18 11:36 Torres 閱讀(12093) | 評(píng)論 (0)編輯 收藏

            C++ Double-ended Queues

            Double-ended queues are like vectors, except that they allow fast insertions and deletions at the beginning (as well as the end) of the container.

            Display all entries for C++ Double-ended Queues on one page, or view entries individually:

            Container constructors create dequeues and initialize them with some data
            Container operators compare, assign, and access elements of a dequeue
            assign assign elements to a dequeue
            at returns an element at a specific location
            back returns a reference to last element of a dequeue
            begin returns an iterator to the beginning of the dequeue
            clear removes all elements from the dequeue
            empty true if the dequeue has no elements
            end returns an iterator just past the last element of a dequeue
            erase removes elements from a dequeue
            front returns a reference to the first element of a dequeue
            insert inserts elements into the dequeue
            max_size returns the maximum number of elements that the dequeue can hold
            pop_back removes the last element of a dequeue
            pop_front removes the first element of the dequeue
            push_back add an element to the end of the dequeue
            push_front add an element to the front of the dequeue
            rbegin returns a reverse_iterator to the end of the dequeue
            rend returns a reverse_iterator to the beginning of the dequeue
            resize change the size of the dequeue
            size returns the number of items in the dequeue
            swap swap the contents of this dequeue with another

            在我看來,deque就是一個(gè)雙端的array,和vector是一摸一樣的,雖然內(nèi)部機(jī)制不一樣
             1/*
             2  Name: C++ DEQUE   
             3  Copyright: 
             4  Author: Torres
             5  Date: 18-08-08 10:55
             6  Description: STL DEQUE 學(xué)習(xí)筆記 
             7*/

             8#include<deque>
             9#include<iostream>
            10#include<algorithm>
            11using namespace std;
            12#define showpass cout<<"pass"<<endl
            13typedef struct point{
            14    double x,y;
            15    point(double a=0,double b=0){
            16        x=a;
            17        y=b;
            18    }

            19}
            point;
            20ostream operator<<(ostream out,point a)
            21{
            22    return out<<a.x<<" "<<a.y<<endl;
            23}

            24
            25void print(point a)
            26{
            27    cout<<a;
            28}

            29int main()
            30{
            31    //deque與vector很相似只不過是兩端都可以存取的vector
            32    deque<point>cp,cp1(10);
            33    int i;
            34    for(i=0;i<5;i++){
            35        point temp(i,i+1);
            36        cp.push_back (temp);
            37    }

            38    
            39    for(i=0;i<5;i++){
            40        cp1[i].x=i;
            41        cp1[i].y=i+1;
            42    }

            43    //取地址符號(hào)[]必須在容器已經(jīng)開辟空間后才能用,push函數(shù)開辟了新空間
            44    for_each(cp.begin(),cp.end(),print);
            45    cout<<endl;
            46    for_each(cp1.begin(),cp1.end()-5,print);
            47    cout<<endl;
            48    
            49    //erase刪除函數(shù)
            50    cp.erase(cp.begin()+1);
            51    for_each(cp.begin(),cp.end(),print);
            52    cout<<endl;
            53    cp1.erase(cp1.begin(),cp1.begin()+3);
            54    for_each(cp1.begin(),cp1.end()-5,print);
            55    cout<<endl;
            56
            57    cout<<cp.front()<<cp.back()<<endl; 
            58
            59
            60    return 0;
            61}

            posted @ 2008-08-18 11:02 Torres 閱讀(654) | 評(píng)論 (0)編輯 收藏

            先看函數(shù):
            C++ Lists

            Lists are sequences of elements stored in a linked list. Compared to vectors, they allow fast insertions and deletions, but slower random access.

            Display all entries for C++ Lists on one page, or view entries individually:

            List constructors create lists and initialize them with some data
            List operators assign and compare lists
            assign assign elements to a list
            back returns a reference to last element of a list
            begin returns an iterator to the beginning of the list
            clear removes all elements from the list
            empty true if the list has no elements
            end returns an iterator just past the last element of a list
            erase removes elements from a list
            front returns a reference to the first element of a list
            insert inserts elements into the list
            max_size returns the maximum number of elements that the list can hold
            merge merge two lists
            pop_back removes the last element of a list
            pop_front removes the first element of the list
            push_back add an element to the end of the list
            push_front add an element to the front of the list
            rbegin returns a reverse_iterator to the end of the list
            remove removes elements from a list
            remove_if removes elements conditionally
            rend returns a reverse_iterator to the beginning of the list
            resize change the size of the list
            reverse reverse the list
            size returns the number of items in the list
            sort sorts a list into ascending order
            splice merge two lists in constant time
            swap swap the contents of this list with another
            unique removes consecutive duplicate elements

            要注意的是list不提隨機(jī)的迭代器,迭代器是個(gè)雙向的,非連續(xù)存儲(chǔ),而且是個(gè)環(huán)狀鏈表在尾端是個(gè)未初始化節(jié)點(diǎn)
            空判斷:begin==end;
            clear  remove  unique(把相同元素移出,留一個(gè)先sort)  insert(插入兩種方式)
            只能使用成員函數(shù) sort,不能使用 算法 sort(他只接受random iterator)

             1/*
             2  Name: C++ STL LIST    
             3  Copyright: 
             4  Author: Torres
             5  Date: 17-08-08 23:28
             6  Description: LIST 學(xué)習(xí)筆記 
             7*/

             8#include<iostream>
             9#include<list>
            10#include<vector>
            11#include<algorithm>
            12using namespace std;
            13typedef struct node{
            14    double x,y;
            15    node (double a=0,double b=0){
            16        x=a;
            17        y=b;
            18    }

            19}
            node;
            20void print(int a){printf("%d ",a);return;}
            21
            22ostream operator <<(ostream out,node a)
            23{
            24    return out<<a.x<<" "<<a.y<<endl;
            25}

            26int main()
            27{
            28    int i,j;
            29
            30    list<node>nlist;
            31    list<int>intlist,intlist1;
            32    
            33    vector<int>intv1,intv2;
            34    intv1.assign(5,7);
            35    intv2.assign(intv1.begin()+1,intv1.end()-1);
            36    for_each(intv2.begin()+1,intv2.end(),print);
            37    cout<<endl;
            38
            39    //assign的用法,有兩種,發(fā)現(xiàn)list的iterator不能夠相加而vector可以
            40    intlist.assign(5,7);
            41    intlist1.assign(intlist.begin(),intlist.end());
            42    for_each(intlist.begin(),intlist.end(),print);
            43    printf("\n");
            44    for_each(intlist1.begin(),intlist1.end(),print);
            45    printf("\n");
            46    
            47    //size的用法,表示實(shí)際數(shù)據(jù)的大小
            48    cout<<intlist.size()<<endl;
            49    //list沒有容量capacity函數(shù)
            50
            51    //因?yàn)閘ist是一個(gè)雙端鏈表,不支持隨機(jī)存取,他的存取必須用iterator來進(jìn)行
            52    //而vector,deque,等容器是支持的。
            53    list<int>::iterator it1;
            54    for(it1=intlist1.begin();it1!=intlist1.end();it1++)
            55        cout<<*it1<<" ";
            56    cout<<endl;
            57
            58    const node cnode(1.0,2.0);
            59    cout<<cnode<<endl;
            60
            61    nlist.assign(5,cnode);
            62    list<node>::iterator it2;
            63    for(it2=nlist.begin();it2!=nlist.end();it2++)
            64        cout<<*it2;
            65    return 0;
            66}

            67

            posted @ 2008-08-17 23:30 Torres 閱讀(664) | 評(píng)論 (0)編輯 收藏

            菜菜的學(xué)習(xí)了一下STL的vector,做一下筆記感覺這個(gè)網(wǎng)站講得通俗易懂http://www.cppreference.com/cppvector/index.html 寫了一下測(cè)試code(待續(xù))

            C++ Vectors

            Vectors contain contiguous elements stored as an array. Accessing members of a vector or appending elements can be done in constant time, whereas locating a specific value or inserting elements into the vector takes linear time.

            Display all entries for C++ Vectors on one page, or view entries individually:

            Vector constructors create vectors and initialize them with some data
            Vector operators compare, assign, and access elements of a vector
            assign assign elements to a vector
            at returns an element at a specific location
            back returns a reference to last element of a vector
            begin returns an iterator to the beginning of the vector
            capacity returns the number of elements that the vector can hold
            clear removes all elements from the vector
            empty true if the vector has no elements
            end returns an iterator just past the last element of a vector
            erase removes elements from a vector
            front returns a reference to the first element of a vector
            insert inserts elements into the vector
            max_size returns the maximum number of elements that the vector can hold
            pop_back removes the last element of a vector
            push_back add an element to the end of the vector
            rbegin returns a reverse_iterator to the end of the vector
            rend returns a reverse_iterator to the beginning of the vector
            reserve sets the minimum capacity of the vector
            resize change the size of the vector
            size returns the number of items in the vector
            swap swap the contents of this vector with another

             1#include<vector>
             2#include<iostream>
             3#include<algorithm>
             4using namespace std;
             5void print(int a){cout<<a<<" ";}
             6int main()
             7{
             8    vector<int>v,v1;
             9    vector<int>::iterator iv1,iv2;
            10    vector<int>v2;
            11    v2.reserve(10);    
            12    v.assign(10,2);
            13    cout<<v2.capacity()<<endl;//capacity容量輸出為10
            14    cout<<v2.size()<<endl;//大小輸出為1
            15    int i;
            16    for(i=0;i<7;i++)v2.push_back(i);
            17    for_each(v2.begin(),v2.end(),print);
            18    cout<<endl;
            19    for(iv1=v2.begin();iv1!=v2.end();iv1++)
            20        if(*iv1==3)break;
            21    if(iv1!=v2.end())v2.insert(iv1,99);
            22    for_each(v2.begin(),v2.end(),print);
            23    cout<<endl;
            24    if(iv1!=v2.end())v2.insert(iv1,5,99);
            25    for_each(v2.begin(),v2.end(),print);
            26    cout<<endl;
            27    if(iv1!=v2.end())v2.insert(iv1,v.begin(),v.end());
            28    for_each(v2.begin(),v2.end(),print);
            29    cout<<endl;
            30    cout<<v2.size()<<endl;
            31    v2.erase(v2.begin());
            32    cout<<v2.size()<<endl;
            33    v2.erase(v2.begin(),v2.end());
            34    for_each(v2.begin(),v2.end(),print);
            35    iv1=v.begin();iv2=v.end();
            36    cout<<v.begin()<<endl;
            37    cout<<v.end()<<endl;
            38    cout<<iv1<<endl;
            39    cout<<iv2<<endl;
            40//    for(i=0;i<15;i++)cout<<v[i]<<" ";
            41//    cout<<endl;
            42//    for(i=0;i<15;i++)cout<<v.at(i)<<" ";//at()函數(shù)更加安全;
            43//    cout<<endl;
            44    for_each(v.begin(),v.end(),print);
            45    cout<<endl;
            46//    v1.assign(v.begin(),v.end());
            47//    v1.assign(iv1+2,iv2-2);
            48//    for(i=0;i<10;i++)cout<<v1[i]<<' ';
            49//    cout<<endl;
            50    for(i=0;i<10;i++)v1.push_back(i);
            51    for_each(v1.begin()+1,v1.end()-2,print);//輸出begin開始指向的數(shù)據(jù),直到end指向的前一個(gè)數(shù)據(jù)
            52    for_each(v1.begin(),v1.end(),print);
            53    cout<<endl;
            54    cout<<v1.back()<<endl;
            55    cout<<v1.front()<<endl;
            56    cout<<v1.size()<<endl;
            57    v.clear();
            58    cout<<v.size()<<endl;
            59    for_each(v.begin(),v.end(),print);//已經(jīng)clear,begin==end,不會(huì)有任何結(jié)果。
            60    return 0;
            61}

            62
            63
            64
            65//試了一下結(jié)構(gòu)體,感覺自己簡(jiǎn)直太水了,努力學(xué)習(xí)中!
            66
            67#include<iostream>
            68#include<vector>
            69using namespace std;
            70typedef struct node{
            71    int x;
            72    int y;
            73}
            node;
            74ostream operator<<(ostream in,node a){
            75    in<<a.x<<a.y<<endl;
            76    return in;
            77}

            78int main()
            79{
            80    vector<node>v(10);
            81    v[0].x=1;v[0].y=1;
            82    vector<node>::iterator iv(v.begin());
            83    cout<<v[0].x<<v[0].y<<endl;
            84    cout<<*iv<<endl;
            85    cout<<iv->x<<iv->y<<endl;
            86    return 0;
            87}
            posted @ 2008-08-13 00:54 Torres 閱讀(167) | 評(píng)論 (0)編輯 收藏

            一直想有一個(gè)blog,做做筆記,整理整理思路,基于這個(gè)思想,這個(gè)blog誕生了!以后就靠這個(gè)來祭奠生活了。
            posted @ 2008-08-11 12:30 Torres 閱讀(180) | 評(píng)論 (1)編輯 收藏

            僅列出標(biāo)題
            共7頁: 1 2 3 4 5 6 7 
            亚洲精品乱码久久久久久不卡| 久久se精品一区二区| 国产精品免费久久久久电影网| 曰曰摸天天摸人人看久久久| 精品久久久久久国产潘金莲 | 久久久这里有精品| 欧美黑人激情性久久| 国产午夜精品久久久久免费视| 久久国产精品99精品国产987| 国产成年无码久久久久毛片| 亚洲国产成人精品久久久国产成人一区二区三区综 | 日韩欧美亚洲综合久久影院Ds| 久久精品亚洲欧美日韩久久| 久久久久亚洲国产| 久久国产精品99久久久久久老狼| 国产精品伦理久久久久久| 97精品依人久久久大香线蕉97| 99精品久久精品| 久久久久久久波多野结衣高潮 | 久久久久久午夜成人影院| 久久国产精品波多野结衣AV| 新狼窝色AV性久久久久久| 精品综合久久久久久98| 久久久久这里只有精品 | 国产精品99久久精品| 四虎影视久久久免费观看| 狠狠色丁香久久综合五月| 久久久久精品国产亚洲AV无码| 亚洲欧美精品伊人久久| 亚洲中文久久精品无码| 日韩久久久久中文字幕人妻 | 亚洲精品乱码久久久久久蜜桃不卡| 精品久久久无码中文字幕天天| 97久久综合精品久久久综合| 无遮挡粉嫩小泬久久久久久久| 久久精品成人一区二区三区| 青青国产成人久久91网| 亚洲国产成人久久精品影视| 99久久99这里只有免费费精品| 久久棈精品久久久久久噜噜| 国产99久久久国产精品小说|