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

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

            晚上花了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'結(jié)束"<<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<<"號結(jié)點"<<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 閱讀(1004) 評論(3)  編輯 收藏 引用

            評論

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

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

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

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

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

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


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


            精品久久久久香蕉网| 日韩欧美亚洲综合久久影院d3| 久久精品99久久香蕉国产色戒 | 国产精品久久久99| 久久久久无码国产精品不卡| 国产免费久久精品99re丫y| 午夜天堂精品久久久久| 欧美777精品久久久久网| 国产成人无码精品久久久免费| 久久久久久亚洲精品影院| 一本色道久久88加勒比—综合| 免费精品久久久久久中文字幕| 久久99精品国产麻豆宅宅| 无码国产69精品久久久久网站| 久久99国产亚洲高清观看首页 | 亚洲AV日韩AV永久无码久久| 国产成人99久久亚洲综合精品| 久久精品人人做人人爽电影| 色狠狠久久综合网| 91精品国产综合久久香蕉 | 国产精品久久久久9999高清| 成人久久免费网站| 久久久久99这里有精品10| 2021久久精品国产99国产精品| 久久WWW免费人成一看片| 久久综合伊人77777麻豆| 国产综合免费精品久久久| 99久久精品这里只有精品 | 国产成人综合久久精品尤物| 久久男人Av资源网站无码软件| 99久久免费国产精品特黄| 一级a性色生活片久久无少妇一级婬片免费放 | 久久精品国产99久久无毒不卡| 久久精品中文无码资源站| 日韩欧美亚洲综合久久| 一级做a爰片久久毛片看看| 亚洲欧美一级久久精品| 久久婷婷人人澡人人| 久久久黄片| 一本久久综合亚洲鲁鲁五月天| 亚洲伊人久久综合中文成人网|