ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

˳Ðò¶ÓÁРQueue(Èý)
2013-11-20 14:24:18 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:373´Î
Tags£ºË³Ðò ¶ÓÁÐ   Queue

 

¡¡¡¡void Compare(){

¡¡¡¡Extended_queue left_queue;

¡¡¡¡char left_char;

¡¡¡¡bool waiting=true;

¡¡¡¡while(cin>>left_char && waiting){

¡¡¡¡if(left_char==':'){

¡¡¡¡waiting=false; //if ':' is entered, quit the left input

¡¡¡¡break;

¡¡¡¡}

¡¡¡¡else if(left_queue.full())

¡¡¡¡cout<<"Queue is full!"<

¡¡¡¡else

¡¡¡¡left_queue.append(left_char);

¡¡¡¡//if the input is not ':' and there is space in the queue

¡¡¡¡//append the charcter to the queue

¡¡¡¡}

¡¡¡¡char right_char;

¡¡¡¡bool same=true;

¡¡¡¡while(!waiting && cin>>right_char){ //if ':' is input before

¡¡¡¡//now input the righter charachters

¡¡¡¡if(left_queue.empty()){

¡¡¡¡cout<<"R"<

¡¡¡¡//and the user is still inputing, right must longer than left

¡¡¡¡//print [R]

¡¡¡¡return;

¡¡¡¡}

¡¡¡¡else{

¡¡¡¡left_queue.serve_and_retrieve(left_char);

¡¡¡¡if(left_char!=right_char)

¡¡¡¡same=false; //if the character input now is different from

¡¡¡¡//the one put into left before, set the bool same to 'false'

¡¡¡¡}

¡¡¡¡}

¡¡¡¡if(waiting){

¡¡¡¡cout<<"N"<

¡¡¡¡//print [N]

¡¡¡¡return ;

¡¡¡¡}

¡¡¡¡if(!left_queue.empty()){

¡¡¡¡cout<<"L"<

¡¡¡¡//left must longer than right

¡¡¡¡//print [L]

¡¡¡¡return ;

¡¡¡¡}

¡¡¡¡if(left_queue.empty() && same){

¡¡¡¡cout<<"S"<

¡¡¡¡//left and right have the exactly same characters

¡¡¡¡//print [S]

¡¡¡¡return;

¡¡¡¡}

¡¡¡¡return;

¡¡¡¡}

¡¡¡¡¡¾¹ý³Ì¼Ç¼¡¿

¡¡¡¡ÊµÑé½ØÍ¼£º

¡¡¡¡¡¾½á¹û·ÖÎö¡¿

¡¡¡¡1.ʵÑéÖÐÎÒÒԿα¾ºóÃæµÄÁ·Ï°ÌâΪÀý£¬ÊµÏÖ²¢ÑéÖ¤ÁË˳Ðò¶ÓÁеĸüÖÖ¹¦ÄÜ¡£

¡¡¡¡2.¶ÓÁÐÓëÕ»Ò»ÑùÊÇÔÚÀàÖÐÒÔÊý×é´æ´¢Êý¾Ý£¬µ«ÓÉÓÚ¶ÓÁÐÏȽøÏȳöµÄÌØµãÔÚʵÏÖ´æ´¢ÐÎʽÉÏÓëÕ»ÓÐÒ»¶¨µÄ²»Í¬¡£ÒòΪÈç¹ûÓëÕ»Ò»Ñù¶ÔÊý¾Ý²Ù×÷£¬¶ÓÁлáÎÞÏÞÏòºóÀ©´ó£¬¶øÇ°ÃæÈ¡³ö¹ýÊý¾ÝµÄµØ·½½«²»»áÔÙ±»ÀûÓã¬Ê®·ÖÀË·Ñ£¬Ò²ºÜÈÝÒ×Òç³ö¡£ËùÒÔÎÒÃDzÉÓÃÑ­»·Êý×éÀ´´æ´¢£¬ÕâÑùºÏÀíÀûÓÃÁË×ÊÔ´¡£µ«ÔÚÀàµÄʵÏÖÒªÒª¼«ÎªÊ±¿Ì¿¼ÂÇÖÜÈ«rearºÍfrontµÄ¸÷ÖÖ¿ÉÄÜ£¬ÒªÅжÏÊDz»ÊÇÑ­»·µ½ÁËÇ°Ãæ£¬countÔÚ´ËʱµÄ¹¦ÄÜÒ²¼«ÎªÍ»³ö¡£

¡¡¡¡3.ÊéÖеijÌÐò¿´ËƼòµ¥£¬µ«Êµ¼ÊÅжϸ÷ÖÖÊä³öÇé¿öµÄʱºòÈ´¼«ÄÑ¿¼ÂÇÖÜÈ«¡£ÎÒÊ×ÏÈ×ö³öÁ˼òÒ×µÄÁ÷³Ìͼ£¬È»ºó²Åдº¯Êý£¬¾ßÌå·ÖÎö¼°Ë¼Â·¿É¼ûÎÒÔ´ÂëµÄ×¢ÊÍ¡£ÁíÍâ±¾Ì⻹ÓÐÁíÍâÒ»ÖÖʵÏÖ˼·£º¼´½«×óÓÒÊäÈë·Ö±ð´æ·ÅÔÚÁ½¸ö¶ÓÁÐÖУ¬±ßȡȥ±ß±È½Ï£¬ÄÇÑùÔÚÂß¼­ÉÏÈÝÒ×Àí½âһЩ¡£µ«¼øÓÚÌâÄ¿µÄÒªÇó£¬ÎÒ»¹ÊÇÓñߴÓ×ó±ß¶ÓÁÐÖÐÈ¡³ö±ß±È½ÏÓÒ±ßÊäÈëµÄ·½·¨¡£

¡¡¡¡4.ÎÒÔÚʵÑéÖÐÓöµ½µÄÎÊÌ⣺

¡¡¡¡(1)×Ô¼ºÒ»¿ªÊ¼ÔÚÑ­»·ÅжÏÓõÄÊÇcin.get()=='\n'¼´Óöµ½»Ø³µ¾ÍÍ£Ö¹ÊäÈ룬µ«È´ÎÞ·¨ÈçÁÏÏëÖнáÊøÑ­»·¡­¡­×îÖÕ²ÉÓÃcin>>a && waiting(ÓÃÒÔ±êÖ¾¡®£º¡¯µÄÊäÈë)À´×÷Ϊѭ»·ÖÕÖ¹µÄÌõ¼þ£¬ÕâÑùËäÈ»¿ÉÒÔÔËÐУ¬µ«Óû§±ØÐëÊäÈëCtrl+¡®Z¡¯ÒÔ½áÊøÊäÈë¡£¿´À´×Ô¼º¶ÔÊäÈëÁ÷µÄÀí½âÓëÕÆÎÕ»¹Ã»Óе½Î»¡£

¡¡¡¡(2)ÁíÍâÔÚ¼ìÑéµÄʱºò£¬ÎÒ·¢ÏÖÊäÈë¡®£º¡¯Ö®Ç°ÊÇ·ñÊäÈë»Ø³µÇé¿öÊÇÓÐÇø±ðµÄ¡£Èç

¡¡¡¡ÊäÈë¡°sam:sam¡±(ÎÞ¿Õ¸ñ)£¬½á¹ûΪ¡°R¡±

¡¡¡¡ÊäÈë¡°sam : sam¡±(Óпոñ)£¬½á¹¹Îª¡°S¡±

¡¡¡¡ÏÔÈ»ºóÕßÊÇÎÒÏ£ÍûµÃµ½µÄ½á¹û£¬ÎÒ·ÖÎö¿ÉÄÜÊÇÇ°ÃæÇé¿ö¡®£º¡¯±»ÁÐÈëÁËrightµÄÅжϣ¬´Ó¶øÊ¹½á¹¹Óұ߱È×ó±ß³¤¡£»¹Ã»ÓÐÏëµ½ÈçºÎ¸Ä½ø¡£

        

Ê×Ò³ ÉÏÒ»Ò³ 1 2 3 ÏÂÒ»Ò³ βҳ 3/3/3
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºË³ÐòÕ» Stack ÏÂһƪ£ºÍ¨¹ý¶þ²æÊ÷ºÍÒ»¸öÊýÕÒµ½Â·¾¶

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)