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


            久久综合伊人77777麻豆| 国产精自产拍久久久久久蜜| 亚洲国产精品无码久久| 久久久女人与动物群交毛片| 精品无码久久久久国产| 久久国产乱子伦免费精品| 四虎国产精品免费久久5151| 国产农村妇女毛片精品久久| 欧美亚洲国产精品久久| 精品国产一区二区三区久久久狼 | 久久99精品国产麻豆宅宅| 国产高潮国产高潮久久久91 | 久久久久久午夜成人影院 | 国产∨亚洲V天堂无码久久久| 国产国产成人久久精品| 久久久国产99久久国产一| 国产精品久久久久影院色| 亚洲精品tv久久久久久久久久| 久久偷看各类wc女厕嘘嘘| 国产精品欧美久久久久天天影视| 国内精品久久久久久久久电影网| 国产精品亚洲综合专区片高清久久久| 久久亚洲熟女cc98cm| 国内精品久久久久久久久| 天堂久久天堂AV色综合| 日韩中文久久| 亚洲综合精品香蕉久久网97 | 久久久久亚洲AV综合波多野结衣| 无码八A片人妻少妇久久| 国产成人精品久久亚洲高清不卡 | 人妻无码αv中文字幕久久| 久久久久亚洲av成人无码电影| av无码久久久久久不卡网站| 怡红院日本一道日本久久| 日韩精品无码久久久久久| 久久久久亚洲AV无码专区桃色| 国产精品久久永久免费| 亚洲午夜无码久久久久| 久久久黄色大片| 尹人香蕉久久99天天拍| 久久久久亚洲?V成人无码|