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

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

            線性表類——張宏數(shù)據(jù)結構第一課

            晚上花了2個多小時寫的,感覺不是很難,下次嘗試下寫成鏈表+模板的形式 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
            <<"請順序鍵入鏈表中的數(shù)值,用空格隔開,并以'-1'結束"<<endl;
                
            int pos=1;
                
            int temp;
                
            while(cin>>temp)
                {
                        
            if(temp==-1)
                        
            break;
                    
            if(lenth>=LISTVOLUME)
                    {

                        cout
            <<"抱歉,線性表已滿,無法輸入數(shù)據(jù),請重新初始化該數(shù)據(jù)表"<<endl;
                        cout
            <<"請問需要重新初始化嗎?(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ù)表已滿,無法添加數(shù)據(jù)"<<endl;
                    
            return;
                }
                
            if(pos<1||pos>lenth+1)
                {

                    cout
            <<"您輸入的位置不合法,請重新輸入(僅需要輸入插入的位置):";
                    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
            <<"您輸入的位置不合法,請重新輸入";
                    cin
            >>pos;
                }
                
            int i;
                
            for(i=pos+1;i<=lenth;i++)
                {

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

                }
                a[lenth]
            =0;
                lenth
            --;
                cout
            <<"成功刪除"<<pos<<"號結點"<<endl;
            }

            void sqlist::sortlist()
            {

                
            int temp;
                cout
            <<"請問您需要從小到大排列(鍵入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<<"號位置"<<endl;
                        
            return ;
                    }


                }
                cout
            <<"沒有搜索到改元素,請重新查找"<<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) 評論(3)  編輯 收藏 引用

            評論

            # re: 線性表類——張宏數(shù)據(jù)結構第一課 2009-02-19 09:13 xxxxx

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

            # re: 線性表類——張宏數(shù)據(jù)結構第一課 2009-02-19 11:40 abilitytao

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

            # re: 線性表類——張宏數(shù)據(jù)結構第一課 2009-02-19 11:44 羅偉濤

            @xxxxx
            另外可不可以請教一下 這個類還能怎樣改進呢?
              回復  更多評論   

            久久久久久国产a免费观看黄色大片| 欧美久久综合性欧美| 久久精品国产精品亚洲人人| 26uuu久久五月天| 免费一级欧美大片久久网| 三级片免费观看久久| 青青草原综合久久大伊人| 亚洲人成伊人成综合网久久久| 久久国产精品无码HDAV| 久久久精品免费国产四虎| 久久久久香蕉视频| 亚洲精品乱码久久久久久蜜桃图片| 精品久久久久久久久午夜福利| 久久精品中文字幕第23页| 青草国产精品久久久久久| 亚洲国产成人久久精品动漫| 香蕉久久AⅤ一区二区三区| 色婷婷综合久久久中文字幕| 久久国产精品偷99| 久久免费的精品国产V∧| 久久久WWW成人免费精品| 色综合久久久久综合体桃花网| 99久久精品无码一区二区毛片 | 色综合久久久久无码专区| 久久精品国产精品青草| 伊人久久久AV老熟妇色| 亚洲乱码日产精品a级毛片久久 | 久久精品国产精品亚洲人人| 久久人做人爽一区二区三区| 欧美日韩精品久久久久| 国产2021久久精品| 99久久人妻无码精品系列蜜桃| 99久久精品免费看国产一区二区三区 | 久久亚洲熟女cc98cm| 久久国产精品免费一区| 日韩欧美亚洲综合久久影院d3| 亚洲AV无码一区东京热久久| 伊人久久精品无码av一区| 18禁黄久久久AAA片| 久久国产精品无| 欧美亚洲国产精品久久|