JavaʵÏÖÑ»·¶ÓÁÐ
import java.io.*;
public class QueueArray {
Object[] a; //¶ÔÏóÊý×飬¶ÓÁÐ×î¶à´æ´¢a.length-1¸ö¶ÔÏó
int front; //¶ÓÊ×ϱê
int rear; //¶Óβϱê
public QueueArray(){
this(10); //µ÷ÓÃÆäËü¹¹Ôì·½·¨
}
public QueueArray(int size){
a = new Object[size];
front = 0;
rear =0;
}
/**
* ½«Ò»¸ö¶ÔÏó×·¼Óµ½¶ÓÁÐβ²¿
* @param obj ¶ÔÏó
* @return ¶ÓÁÐÂúʱ·µ»Øfalse,·ñÔò·µ»Øtrue
*/
public boolean enqueue(Object obj){
if((rear+1)%a.length==front){
return false;
}
a[rear]=obj;
rear = (rear+1)%a.length;
return true;
}
/**
* ¶ÓÁÐÍ·²¿µÄµÚÒ»¸ö¶ÔÏó³ö¶Ó
* @return ³ö¶ÓµÄ¶ÔÏ󣬶ÓÁпÕʱ·µ»Ønull
*/
public Object dequeue(){
if(rear==front){
return null;
Ïà¹ØÎĵµ£º
Õ⼸ÌìÒ»Ö±ÔÚ¸ã¹ØÓÚÓÅÏȼ¶¶ÓÁеÄʵÏÖ,ÒòΪҪ¿¼Âǵ½Ï̵߳ݲȫ,ËùÒÔPriorityQueue¾Í²»ÊÊÓÃÁË¡£Ò»¸ö·Ç³£¼òµ¥µÄʵÏÖ·½
·¨£¬ÄǾÍÊÇ°ÑÓÅÏȼ¶±È½ÏºÃµÄ²åÈëÒ»¸ö¶ÓÁУ¬ÓÅÏȼ¶µÍµÄ²åÈëÁíÒ»¸ö¶ÓÁУ¬È¡ÊýµÄʱºòÏÈÔÚÓÅÏȼ¶¸ßµÄ¶ÓÁÐÉÏÈ¡Êý¡£ÕâÓиöȱµã¾ÍÊÇÈç¹ûÓÅÏȼ¶±ðÔ½¶àµÄ»°£¬¶ÓÁ ......
ÎÒÃÇÖªµÀ£¬ÔÚJavaÖÐÉèÖñäÁ¿ÖµµÄ²Ù×÷£¬³ýÁËlongºÍ doubleÀàÐ͵ıäÁ¿ÍⶼÊÇÔ×Ó²Ù×÷£¬Ò²¾ÍÊÇ˵£¬¶ÔÓÚ±äÁ¿ÖµµÄ¼òµ¥¶Áд²Ù×÷ûÓбØÒª½øÐÐͬ²½¡£ÕâÔÚJVM 1.2֮ǰ£¬JavaµÄÄÚ´æÄ£ÐÍʵÏÖ×ÜÊÇ´ÓÖ÷´æ¶ÁÈ¡±äÁ¿£¬ÊDz»ÐèÒª½øÐÐÌرðµÄ×¢ÒâµÄ¡£¶øËæ×ÅJVMµÄ³ÉÊìºÍÓÅ»¯£¬ÏÖÔÚÔÚ¶àÏ̻߳·¾³ÏÂvolatile¹Ø¼ü×ÖµÄʹÓñäµÃ·Ç³£ÖØÒª¡£ÔÚµ±Ç°µ ......
ÔÚÉÐѧÌÃѧÍêjavaÈÃÎÒÇáËɸ㶨¹¤×÷
¡¾Ñ§Ô±¹ÊÊ¡¿À´×ÔÉÐѧÌÃÕæÈËÕæÊ &n ......
³õʼ»¯µÄʵ¼Ê¹ý³ÌΪ£º
ÔÚÆäËüÈκÎÊÂÎï·¢Éú֮ǰ£¬½«·ÖÅä¸ø¶ÔÏóµÄ´æ´¢¿Õ¼ä³õʼ»¯³É¶þ½øÖƵÄÁã¡£
¸¸Ààstatic ¿é»ò±äÁ¿
×ÓÀàstatic¿é»ò±äÁ¿
¸¸ÀàµÄÏÔʽ³õʼ»¯
¸¸À๹Ô캯Êý
×ÓÀàµÄÏÔʽ³õʼ»¯
×ÓÀàµÄ¹¹Ô캯Êý
´Ë¹ý³ÌÖÐÈôÓи¸À๹ÔìÌåÖе÷Ó÷½·¨¿É±»×ÓÀàÖØÔØ£¬ÔòJVM»á´Ó×îµÍ×ÓÀà¶ÔÏó´¦Ñ°ÕÒ´Ë·½·¨£¬ÕÒµ½ÔòÖ´ÐУ¬ËäÈ»´Ëʱ¶Ô ......