• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            看到首頁上有人寫,自己也寫了一個

            名字起錯了,其實寫個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菜鳥 閱讀(376) 評論(1)  編輯 收藏 引用

            Feedback

            # re: josephon問題 2011-03-16 11:31 Husiwa
            不過這個模擬過程非常不好,對于100000以上的人數來說簡直就是悲劇。。。
              回復  更多評論
              

            亚洲精品高清久久| 99精品国产99久久久久久97| 精品久久久久久久久午夜福利| 久久久久99精品成人片试看| 国产午夜久久影院| 欧美亚洲国产精品久久| 亚洲中文字幕无码一久久区| 国产AV影片久久久久久| 亚洲精品国产综合久久一线| 久久综合狠狠综合久久| 久久久久久久综合综合狠狠| 亚洲国产精品一区二区久久hs | 69SEX久久精品国产麻豆| 99久久免费国产精品| 久久久久久国产精品无码下载| 久久中文娱乐网| 99久久精品免费看国产一区二区三区 | 亚洲色婷婷综合久久| 精品久久久久久无码人妻蜜桃 | 伊人色综合九久久天天蜜桃| 999久久久无码国产精品| 99久久综合国产精品免费| 久久久久九国产精品| 久久精品国产网红主播| 亚洲精品无码久久久久| 亚洲&#228;v永久无码精品天堂久久 | 无码超乳爆乳中文字幕久久| 色婷婷久久久SWAG精品| 久久99精品国产麻豆婷婷| 久久免费视频网站| 精品九九久久国内精品| 国产亚洲欧美成人久久片| www久久久天天com| 97久久精品国产精品青草| 久久国产精品成人影院| 一本色道久久99一综合| 日韩人妻无码一区二区三区久久| 少妇久久久久久被弄到高潮| 久久午夜福利电影| 精品国产99久久久久久麻豆 | 久久久无码一区二区三区 |