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

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語(yǔ)默心酸。二十光陰無(wú)一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            線性表類(lèi)——張宏數(shù)據(jù)結(jié)構(gòu)第一課

            晚上花了2個(gè)多小時(shí)寫(xiě)的,感覺(jué)不是很難,下次嘗試下寫(xiě)成鏈表+模板的形式 O(∩_∩)O~

            #include<iostream>
            #include
            <algorithm>
            using namespace std;

            #define LISTVOLUME 10000


            class sqlist
            {
            private:
                
            int a[10001];
                
            int lenth;
                
            int max;
            public:
                sqlist()
                {
                    memset(a,
            0,sizeof(a));
                    lenth
            =0;
                    max
            =LISTVOLUME;


                }
                
            void initial();
                
            void creat();
                
            void print();
                
            void inset(int num,int pos);
                
            void deletenode(int pos);
                
            void sortlist();
                
            int size();
                
            bool empty();
                
            bool full();
                
            void findnode(int num);


            };


            void sqlist::initial()
            {
                memset(a,
            0,sizeof(a));
                lenth
            =0;
                max
            =LISTVOLUME;
            }
            void sqlist::creat()
            {

                cout
            <<"請(qǐng)順序鍵入鏈表中的數(shù)值,用空格隔開(kāi),并以'-1'結(jié)束"<<endl;
                
            int pos=1;
                
            int temp;
                
            while(cin>>temp)
                {
                        
            if(temp==-1)
                        
            break;
                    
            if(lenth>=LISTVOLUME)
                    {

                        cout
            <<"抱歉,線性表已滿,無(wú)法輸入數(shù)據(jù),請(qǐng)重新初始化該數(shù)據(jù)表"<<endl;
                        cout
            <<"請(qǐng)問(wèn)需要重新初始化嗎?(Y/N)"<<endl;
                        
            char temp;
                        cin
            >>temp;
                        
            if(temp=='Y'||temp=='y')
                        {

                            initial();
                            creat();
                            
            break;
                        }
                        
            else
                            
            break;
                    }

                
                    a[pos]
            =temp;
                    pos
            ++;
                    lenth
            ++;

                    

                }

            }

            void sqlist::print()
            {

                
            int i;
                
            for(i=1;i<=lenth;i++)
                {

                    cout
            <<a[i]<<' ';

                }
                cout
            <<endl;

            }

            void sqlist::inset(int num, int pos)
            {

                
            if(lenth>=LISTVOLUME)
                {

                    cout
            <<"數(shù)據(jù)表已滿,無(wú)法添加數(shù)據(jù)"<<endl;
                    
            return;
                }
                
            if(pos<1||pos>lenth+1)
                {

                    cout
            <<"您輸入的位置不合法,請(qǐng)重新輸入(僅需要輸入插入的位置):";
                    cin
            >>pos;
                }
                
            int i;
                
            for(i=lenth;i>=pos;i--)
                {
                    a[i
            +1]=a[i];
                }
                a[pos]
            =num;
                lenth
            ++;

            }

            void sqlist::deletenode(int pos)
            {
                
            if(pos<1||pos>lenth)
                {

                    cout
            <<"您輸入的位置不合法,請(qǐng)重新輸入";
                    cin
            >>pos;
                }
                
            int i;
                
            for(i=pos+1;i<=lenth;i++)
                {

                    a[i
            -1]=a[i];

                }
                a[lenth]
            =0;
                lenth
            --;
                cout
            <<"成功刪除"<<pos<<"號(hào)結(jié)點(diǎn)"<<endl;
            }

            void sqlist::sortlist()
            {

                
            int temp;
                cout
            <<"請(qǐng)問(wèn)您需要從小到大排列(鍵入1)還是從大到小排列(鍵入-1)"<<endl;
                cin
            >>temp;
                
            if(temp==1)
                    sort(a
            +1,a+1+lenth);
                
            else if(temp==-1)
                {

                    sort(a
            +1,a+1+lenth);
                    reverse(a
            +1,a+1+lenth);

                }
                cout
            <<"排序完成"<<endl;
            }
            int sqlist::size()
            {
                
            return lenth;
            }

            bool sqlist::empty()
            {

                
            if(lenth==0)
                    
            return true;
                
            else
                    
            return false;
            }

            bool sqlist::full()
            {

                
            if(lenth>=max)
                    
            return true;
                
            else
                    
            return false;

            }

            void sqlist::findnode (int num)
            {

                
            int i;
                
            for(i=1;i<=lenth;i++)
                {

                    
            if(a[i]==num)
                    {
                        cout
            <<"該元素位于"<<i<<"號(hào)位置"<<endl;
                        
            return ;
                    }


                }
                cout
            <<"沒(méi)有搜索到改元素,請(qǐng)重新查找"<<endl;
            }





            int main ()
            {
                sqlist test;
                
            int m,n;
                cin
            >>m>>n;
                test.creat();
                test.print();
                test.initial();
                test.creat();
                test.print();
                test.inset(m,n);
                test.sortlist ();
                test.deletenode(
            3);
                test.findnode(
            3);
                
            return 0;

            }



            posted on 2009-02-19 00:51 abilitytao 閱讀(1001) 評(píng)論(3)  編輯 收藏 引用

            評(píng)論

            # re: 線性表類(lèi)——張宏數(shù)據(jù)結(jié)構(gòu)第一課 2009-02-19 09:13 xxxxx

            只是一個(gè)靜態(tài)數(shù)組嘛,而且還有錯(cuò) LISTVOLUME 已經(jīng)越界了  回復(fù)  更多評(píng)論   

            # re: 線性表類(lèi)——張宏數(shù)據(jù)結(jié)構(gòu)第一課 2009-02-19 11:40 abilitytao

            才上了一節(jié)數(shù)據(jù)結(jié)構(gòu)啊 還希望大牛您多多指點(diǎn)啊
            至于那個(gè)宏是后面定義的 開(kāi)始調(diào)的時(shí)候值比較小 之后忘記把數(shù)組改大一點(diǎn)了
            o(╯□╰)o...
              回復(fù)  更多評(píng)論   

            # re: 線性表類(lèi)——張宏數(shù)據(jù)結(jié)構(gòu)第一課 2009-02-19 11:44 羅偉濤

            @xxxxx
            另外可不可以請(qǐng)教一下 這個(gè)類(lèi)還能怎樣改進(jìn)呢?
              回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            国产成人精品免费久久久久| 无码国内精品久久人妻麻豆按摩| 狠狠88综合久久久久综合网| 精品综合久久久久久97超人| 久久久久久青草大香综合精品| 国内精品伊人久久久影院| 久久精品国产亚洲AV高清热| 久久九九久精品国产| 日韩精品久久久久久免费| 狠狠色噜噜色狠狠狠综合久久| 国产∨亚洲V天堂无码久久久| 午夜视频久久久久一区| 国产亚洲精久久久久久无码| 亚洲精品国产综合久久一线| 国产精品久久国产精品99盘| 久久亚洲国产成人影院| 超级碰久久免费公开视频| 久久亚洲精品成人av无码网站| 亚洲Av无码国产情品久久| 久久久青草久久久青草| 人妻精品久久久久中文字幕69| 中文精品久久久久人妻| 国产精品久久久99| 国内精品久久久久| 久久精品无码一区二区无码| 久久99精品久久久大学生| 久久久久久国产精品美女| 国产精品99久久久久久董美香 | 欧美久久综合九色综合| 狠狠色噜噜狠狠狠狠狠色综合久久| 午夜天堂精品久久久久| 久久久久亚洲AV无码观看| 一本色道久久综合狠狠躁篇| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 国产ww久久久久久久久久| 久久国产精品一国产精品金尊| 亚洲欧美成人综合久久久| 影音先锋女人AV鲁色资源网久久 | 91精品国产色综合久久| 男女久久久国产一区二区三区| 欧美va久久久噜噜噜久久|