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


            93精91精品国产综合久久香蕉| 国产日韩久久久精品影院首页| 伊人久久大香线蕉无码麻豆| 无码人妻久久一区二区三区蜜桃 | 亚洲精品tv久久久久| 久久久久久久波多野结衣高潮 | 亚洲精品无码成人片久久| WWW婷婷AV久久久影片| 久久99精品久久久久久水蜜桃| 精品久久久无码人妻中文字幕| 日韩欧美亚洲综合久久影院d3| 一本色道久久88综合日韩精品 | 四虎影视久久久免费观看| 亚洲人成无码久久电影网站| 97久久精品人妻人人搡人人玩 | 色综合久久综合网观看| 久久亚洲国产精品成人AV秋霞| 国产叼嘿久久精品久久| 久久久久久九九99精品| 久久无码AV中文出轨人妻| 久久国产高清字幕中文| 久久精品中文字幕大胸| 一本一道久久精品综合| 青青草原精品99久久精品66| 国内精品欧美久久精品| 狠狠色噜噜狠狠狠狠狠色综合久久| 午夜精品久久久久久影视777 | 伊人 久久 精品| 久久久久久国产精品免费免费| 久久亚洲高清观看| 精品久久人妻av中文字幕| 久久久亚洲裙底偷窥综合| 人妻无码精品久久亚瑟影视| 99久久99久久精品国产片| 狠狠色噜噜狠狠狠狠狠色综合久久| 99久久精品免费看国产一区二区三区 | 国产成人AV综合久久| 色综合久久天天综合| 国产成人精品久久一区二区三区av| 国产精品久久久久久影院 | 久久久久高潮毛片免费全部播放 |