• <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以上的人數來說簡直就是悲劇。。。
              回復  更多評論
              

            2020久久精品亚洲热综合一本| 久久青青国产| 国产成人精品三上悠亚久久| 一本久道久久综合狠狠爱| 久久久国产精华液| 99999久久久久久亚洲| 国产精品99久久久久久董美香| 国产成人AV综合久久| 久久综合久久综合亚洲| 国产成人久久精品一区二区三区| 亚洲国产精品无码久久久不卡| 亚洲日本va中文字幕久久| 久久久久无码精品国产不卡| 国产成人香蕉久久久久| 久久亚洲国产最新网站| 精品久久久无码人妻中文字幕豆芽 | 久久精品国产精品亚洲精品| 久久精品成人免费观看97| 久久久久亚洲AV成人网人人网站| 久久精品国产精品青草| 久久亚洲AV无码精品色午夜麻豆| 国产精品久久久久9999| 国产毛片欧美毛片久久久| 91精品婷婷国产综合久久| 97精品依人久久久大香线蕉97 | 精品无码久久久久国产| 久久久久亚洲AV成人网人人网站| 久久精品国产亚洲av水果派 | 伊人久久五月天| 亚洲成人精品久久| 97热久久免费频精品99| 久久久噜噜噜久久熟女AA片| 亚洲乱码日产精品a级毛片久久| 国产成人无码精品久久久免费| 久久国产精品无码一区二区三区 | 国产成人久久精品一区二区三区| 国产精品99久久久精品无码| 日日狠狠久久偷偷色综合96蜜桃| 国产AV影片久久久久久 | 亚洲国产精品婷婷久久| 国内精品久久久久影院优|