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

            Where there is a dream ,there is hope

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            看到首頁(yè)上有人寫(xiě),自己也寫(xiě)了一個(gè)

            名字起錯(cuò)了,其實(shí)寫(xiě)個(gè)stack更合適

            //!Node information
            //!
            struct Node
            {
                
            int serialNumber;
                
            int flag;
                
            struct Node* next;
            }
            ;

            struct List
            {
                Node
            * head;

                List()
                
            {
                    head
            = NULL;
                }

                
            ~List()
                
            {
                    
            if (head==NULL)
                    
            {
                        
            return;
                    }


                    Node
            * p=head;
                    Node
            * q=head->next;

                    
            while(q!=NULL)
                    
            {
                        delete p;
                        p
            =q;
                        q
            =q->next;
                    }


                    delete p;
                    p
            =NULL;
                    

                }

                
                
            void init(int size)
                
            {
                    
            int i=1;
                    
            while(i<=size)
                    
            {
                        
                        push(size
            -i+1);
                        i
            ++;
                    }

                }

                
            //! the last one is the head
                void push(int i)
                
            {
                    Node
            * pNew=new Node();
                    pNew
            ->serialNumber= i;
                    pNew
            ->flag= 1;
                    pNew
            ->next=head;
                    head
            =pNew;
                }

                
                
            void showAll()
                
            {
                    
            if (head==NULL)
                    
            {
                        
            return;
                    }


                    Node
            * temp=head;

                    
            while(temp)
                    
            {
                        
            if (temp->flag==1)
                        
            {
                            printf(
            "%d  ", temp->serialNumber);
                        }

                        
                        temp
            =temp->next;
                        
                    }


                    printf(
            "\n");
                }


                
            int pop()
                
            {
                    
            int result=0;

                    
            if (head==NULL)
                    
            {
                        
            return result;
                    }


                    Node
            * temp=head;
                    result
            = head ->serialNumber;
                    head
            = head->next;
                    delete temp;
                    
            return result;
                }


                
            void kickOut(int circleNum, int liveNum)
                
            {
                    Node
            * temp=head;
                    
            while( lenLive() > liveNum )
                    
            {
                        
                        
            for (int i=0; i<circleNum;i++ )
                        
            {
                            
            if (temp->flag == 0)
                            
            {
                                i
            --;
                            }

                            
            if (i==( circleNum-1)&&temp->flag==1 )
                            
            {
                                temp
            ->flag = 0;
                            }

                            
                            temp
            =temp->next;
                            
            if (temp==NULL)
                            
            {
                                temp
            =head;
                            }


                        }


                        showAll();
                        printf(
            "\n");
                    }

                }


                
            int len()
                
            {
                    
            if (head==NULL)
                    
            {
                        
            return 0;
                    }

                    Node
            * temp=head;
                    
            int count=0;
                    
            while(temp)
                    
            {

                        count
            ++;
                        temp
            =temp->next;
                    }

                    
            return count;
                }


                
            int lenLive()
                
            {
                    
            if (head==NULL)
                    
            {
                        
            return 0;
                    }

                    Node
            * temp=head;
                    
            int count=0;
                    
            while(temp)
                    
            {
                        
            if (temp->flag == 1)
                        
            {
                            count
            ++;
                        }

                        
                        temp
            =temp->next;
                    }

                    
            return count;
                }


            }
            ;


            //main.cpp
            #include <stdio.h>
            #include 
            <stdlib.h>
            #include 
            "list.h"

            int main()
            {
                
                
            int size=0;
                
            while(true)
                
            {
                    List liveList;
                    scanf(
            "%d"&size);

                    liveList.init(size);

                    printf(
            "liveList len: %d \n", liveList.len());

                    liveList.kickOut(
            32);

                    liveList.showAll();
                }


                
            return 0;
            }
            posted on 2011-03-16 10:58 IT菜鳥(niǎo) 閱讀(370) 評(píng)論(1)  編輯 收藏 引用

            Feedback

            # re: josephon問(wèn)題 2011-03-16 11:31 Husiwa
            不過(guò)這個(gè)模擬過(guò)程非常不好,對(duì)于100000以上的人數(shù)來(lái)說(shuō)簡(jiǎn)直就是悲劇。。。
              回復(fù)  更多評(píng)論
              


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


            久久精品视屏| 久久免费精品一区二区| 婷婷久久综合| 伊人久久大香线蕉亚洲| 久久久久AV综合网成人| 久久精品人人做人人爽电影| 精品人妻伦九区久久AAA片69| 欧美黑人激情性久久| 国内精品人妻无码久久久影院 | 日本精品久久久久影院日本| 漂亮人妻被中出中文字幕久久| 久久久久久亚洲精品成人| 久久AAAA片一区二区| 久久亚洲美女精品国产精品| 日韩欧美亚洲国产精品字幕久久久| 亚洲精品无码久久一线| 日产久久强奸免费的看| 91久久精品无码一区二区毛片| 2019久久久高清456| 丰满少妇人妻久久久久久4| 久久久久久人妻无码| 久久国产欧美日韩精品免费| 色综合久久最新中文字幕| 久久人人爽爽爽人久久久| 欧美一级久久久久久久大| 成人国内精品久久久久影院VR| 久久久女人与动物群交毛片| 一本久久a久久精品综合香蕉| 中文字幕亚洲综合久久2| 国产精品久久免费| 久久偷看各类wc女厕嘘嘘| 久久人人爽人人爽人人av东京热| 国产精品成人无码久久久久久 | 亚洲国产精品久久久天堂| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久国产精品-久久精品| 久久ZYZ资源站无码中文动漫| 精品伊人久久大线蕉色首页| 2020国产成人久久精品| 99精品久久久久久久婷婷| 久久久无码精品亚洲日韩京东传媒|