¶ÓÁÐÊÇÒ»ÖÖÌØÊâµÄÏßÐÔ±í£¬ÌØÊâÖ®´¦ÔÚÓÚËüÖ»ÔÊÐíÔÚ±íµÄÇ°¶Ë£¨front£©½øÐÐɾ³ý²Ù×÷£¬¶øÔÚ±íµÄºó¶Ë£¨rear£©½øÐвåÈë²Ù×÷£¬ºÍÕ»Ò»Ñù£¬¶ÓÁÐÊÇÒ»ÖÖ²Ù×÷ÊÜÏÞÖƵÄÏßÐÔ±í¡£½øÐвåÈë²Ù×÷µÄ¶Ë³ÆΪ¶Ó⣬½øÐÐɾ³ý²Ù×÷µÄ¶Ë³ÆΪ¶ÓÍ·¡£¶ÓÁÐÖÐûÓÐÔªËØʱ£¬³ÆΪ¿Õ¶ÓÁС£
¶ÓÁеÄÊý¾ÝÔªËØÓÖ³ÆΪ¶ÓÁÐÔªËØ¡£ÔÚ¶ÓÁÐÖвåÈëÒ»¸ö¶ÓÁÐÔªËسÆΪÈë¶Ó£¬´Ó¶ÓÁÐÖÐɾ³ýÒ»¸ö¶ÓÁÐÔªËسÉΪ³ö¶Ó¡£ÒòΪ¶ÓÁÐÖ»ÔÊÐíÔÚÒ»¶Ë²åÈ룬ÔÚÁíÒ»¶Ëɾ³ý£¬ËùÒÔÖ»ÓÐ×îÔç½øÈë¶ÓÁеÄÔªËزÅÄÜ×îÏÈ´Ó¶ÓÁÐÖÐɾ³ý£¬¹Ê¶ÓÁÐÓÖ³ÆΪÏȽøÏȳö£¨FIFO¡ªfirst in first out£©ÏßÐÔ±í¡£
˳Ðò¶ÓÁÐ
½¨Á¢Ë³Ðò¶ÓÁнṹ±ØÐëΪÆ侲̬·ÖÅä»ò¶¯Ì¬ÉêÇëһƬÁ¬ÐøµÄ´æ´¢¿Õ¼ä£¬²¢ÉèÖÃÁ½¸öÖ¸Õë½øÐйÜÀí¡£Ò»¸öÊǶÓÍ·Ö¸Õëfront£¬ËüÖ¸Ïò¶ÓÍ·ÔªËØ£»ÁíÒ»¸öÊǶÓβָÕërear£¬ËüÖ¸ÏòÏÂÒ»¸öÈë¶ÓÔªËصĴ洢λÖã¬ÈçͼËùʾ
ÿ´ÎÔÚ¶Óβ²åÈëÒ»¸öÔªËØÊÇ£¬rearÔö1£»Ã¿´Î°¥¶Óͷɾ³ýÒ»¸öÔªËØʱ£¬frontÔö1¡£Ëæ×ŲåÈëºÍɾ³ý²Ù×÷µÄ½øÐУ¬¶ÓÁÐÔªËصĸöÊý²»¶Ï±ä»¯£¬¶ÓÁÐËùÕ¼µÄ´æ´¢¿Õ¼äÒ²ÔÚΪ¶ÓÁнṹËù·ÖÅäµÄÁ¬Ðø¿Õ¼äÖÐÒƶ¯¡£µ±front=rearʱ£¬¶ÓÁÐÖÐûÓÐÈκÎÔªËØ£¬³ÆΪ¿Õ¶ÓÁС£µ±rearÔö¼Óµ½Ö¸Ïò·ÖÅäµÄÁ¬Ðø¿Õ¼äÖ®Íâʱ£¬¶ÓÁÐÎÞ·¨ÔÙ²åÈëÐÂÔªËØ£¬µ«ÕâʱÍùÍù»¹ÓдóÁ¿¿ÉÓÿռäδ±»Õ¼Óã¬ÕâЩ¿Õ¼äÊÇÒѾ³ö¶ÓµÄ¶Ó
ÁÐÔªËØÔø¾Õ¼ÓùýµÄ´æ´¢µ¥Ôª¡£
˳Ðò¶ÓÁÐÖеÄÒç³öÏÖÏó£º
£¨1£© "ÏÂÒç"ÏÖÏ󣺵±¶ÓÁÐΪ¿Õʱ£¬×ö³ö¶ÓÔËËã²úÉúµÄÒç³öÏÖÏ󡣡°ÏÂÒ硱ÊÇÕý³£ÏÖÏ󣬳£ÓÃ×÷³ÌÐò¿ØÖÆתÒƵÄÌõ¼þ¡£
£¨2£©"ÕæÉÏÒç"ÏÖÏ󣺵±¶ÓÁÐÂúʱ£¬×ö½øÕ»ÔËËã²úÉú¿Õ¼äÒç³öµÄÏÖÏ󡣡°ÕæÉÏÒ硱ÊÇÒ»ÖÖ³ö´í״̬£¬Ó¦Éè·¨±ÜÃâ¡£
£¨3£©"¼ÙÉÏÒç"ÏÖÏó£ºÓÉÓÚÈë¶ÓºÍ³ö¶Ó²Ù×÷ÖУ¬Í·Î²Ö¸ÕëÖ»Ôö¼Ó²»¼õС£¬ÖÂʹ±»É¾ÔªËصĿռäÓÀÔ¶ÎÞ·¨ÖØÐÂÀûÓᣵ±¶ÓÁÐÖÐʵ¼ÊµÄÔªËظöÊýԶԶСÓÚÏòÁ¿¿Õ¼äµÄ¹æģʱ£¬Ò²¿ÉÄÜÓÉÓÚβָÕëÒѳ¬Ô½ÏòÁ¿¿Õ¼äµÄÉϽç¶ø²»ÄÜ×öÈë¶Ó²Ù×÷¡£¸ÃÏÖÏó³ÆΪ"¼ÙÉÏÒç"ÏÖÏó¡£
3.Ñ»·¶ÓÁÐ
ÔÚʵ¼ÊʹÓöÓÁÐʱ£¬ÎªÁËʹ¶ÓÁпռäÄÜÖظ´Ê¹Óã¬ÍùÍù¶Ô¶ÓÁеÄʹÓ÷½·¨ÉԼӸĽø£ºÎÞÂÛ²åÈë»òɾ³ý£¬Ò»µ©rearÖ¸ÕëÔö1»òfrontÖ¸ÕëÔö1 ʱ³¬³öÁËËù·ÖÅäµÄ¶ÓÁпռ䣬¾ÍÈÃËüÖ¸ÏòÕâƬÁ¬Ðø¿Õ¼äµÄÆðʼλÖá£×Ô¼ºÕæ´ÓMaxSize-1Ôö1±äµ½0£¬¿ÉÓÃÈ¡ÓàÔËËãrear%MaxSizeºÍfront%MaxSizeÀ´ÊµÏÖ¡£Õâʵ¼ÊÉÏÊǰѶÓÁпռäÏëÏó³ÉÒ»¸ö»·Ðοռ䣬»·ÐοռäÖеĴ洢µ¥ÔªÑ»·Ê¹Óã¬ÓÃÕâÖÖ·½·¨¹ÜÀíµÄ¶ÓÁÐÒ²¾Í³ÆΪѻ·¶ÓÁС£´¦ÁËһЩ¼òµ¥Ó¦ÓÃÖ®Í⣬ÕæÕýʵÓõĶÓÁÐʱѻ·¶ÓÁС£
ÔÚÑ»·¶ÓÁÐÖУ¬µ±¶ÓÁÐΪ¿Õʱ£¬ÓÐfront=rear£¬¶øµ±ËùÓжÓÁпռäÈ«Õ¼Âúʱ£¬Ò²ÓÐfront=rear¡£ÎªÁËÇø±ðÕâÁ½ÖÖÇé¿ö£¬¹æ¶¨Ñ»·¶ÓÁÐ×î¶àÖ»ÄÜÓÐMaxSize-1¸ö¶ÓÁÐÔªËØ£¬µ±Ñ»·¶ÓÁÐÖÐֻʣÏÂÒ»¸ö¿Õ´æ´¢µ¥ÔªÊ±£¬¶ÓÁоÍÒѾÂúÁË¡£Òò´Ë£¬¶ÓÁÐÅпյÄÌõ¼þʱfront=rear£¬¶ø¶ÓÁÐÅÐÂúµÄÌõ¼þʱfront=£¨rear+1£©%MaxSize¡£¶Ó¿ÕºÍ¶ÓÂúµÄÇé¿ö