• <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++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              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以上的人數(shù)來說簡直就是悲劇。。。
              回復  更多評論
              

            久久精品国产男包| 久久久精品国产sm调教网站| 国产精品久久99| 成人久久免费网站| 97久久国产综合精品女不卡| 国产精品美女久久福利网站| 一级A毛片免费观看久久精品| 久久精品无码一区二区app| 亚洲一区二区三区日本久久九| www.久久99| 久久99国产精一区二区三区| 狠狠88综合久久久久综合网| 91久久精一区二区三区大全| 久久99国产精品久久| 国产69精品久久久久9999| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品综合久久久久久98| 欧美伊人久久大香线蕉综合 | 国产免费久久精品99re丫y| AV无码久久久久不卡蜜桃| 久久九九精品99国产精品| 亚洲欧美精品伊人久久| 久久久久国产精品麻豆AR影院 | 久久精品草草草| 久久久这里有精品中文字幕| 97视频久久久| 久久99免费视频| 亚洲&#228;v永久无码精品天堂久久 | 色狠狠久久综合网| 久久精品无码一区二区无码 | 午夜视频久久久久一区 | 久久精品成人免费网站| 久久精品国产一区二区电影| 囯产极品美女高潮无套久久久| 成人资源影音先锋久久资源网| 久久精品国产精品亜洲毛片 | 久久久久久久综合日本亚洲| 久久精品极品盛宴观看| 久久青青草原国产精品免费 | 久久久久久综合网天天| 日本三级久久网|