JavaÊý¾Ý½á¹¹ºÍËã·¨ Õ»Óë¶ÓÁÐ
(1)Õ»
package ChapterOne;
public class Stack {
//Õ»Êý×é
long stackArr[];
//Õ»µÄ´óС
int maxSize;
//Õ»µÄ¶¥²¿
int top;
//³õʼ»¯Ò»¸ö´óСΪsizeµÄÕ»
public Stack(int size){
maxSize = size;
stackArr = new long[size];
top = -1;
}
//³öÕ»²Ù×÷
public long pop(){
return stackArr[top--];
}
//½øÕ»²Ù×÷
public void push(long value){
stackArr[++top] = value;
}
//ÅжÏÕ»ÊÇ·ñΪ¿Õ
public boolean isEmpty(){
return top == -1;
}
//ÅжÏÕ»ÊÇ·ñÒÑÂú
public boolean isFull(){
return top == maxSize-1;
}
//ȡջ¶¥ÔªËØ
public long peek(){
return stackArr[top];
}
public static void main(String[] args) {
Stack stack = new Stack(10);
while(!stack.isFull()){
long v = (long) (Math.random()*100);
stack.push(v);
System.out.print(v+" ");
}
System.out.println();
while(!stack.isEmpty()){
long topValue = stack.pop();
System.out.print(topValue+" ");
}
System.out.println();
}
}
(2)¶ÓÁÐ
package ChapterOne;
public class Queue {
//¶ÓÁÐÊý×é
private long queueArr[];
//¶ÓÁеÄǰ¶Ëϱê
private int front;
//¶ÓÁеÄβ¶Ëϱê
private int rear;
//¶ÓÁеĴóС
private int maxSize;
//¶ÓÁÐÖÐÔªËØµÄ¸öÊý
private int nItems;
//³õʼ»¯Ò»¸ö´óСΪsizeµÄ¶ÓÁÐ
public Queue(int size){
queueArr = new long[size];
maxSize = size;
front = 0;
rear = -1;
nItems = 0;
}
//²åÈë²Ù×÷
public void insert(long value){
//¶ÓÁÐÒÑÂú
if(rear == maxSize-1)
rear = -1;
queueArr[++rear] = value;
nItems++;
}
//ɾ³ý²Ù×÷
public long remove(){
long temp = queueArr[front++];
if(front == maxSize)
front = 0;
nItems--;
return temp;
}
//·µ»Ø¶ÓÁеÚÒ»¸öÔªËØ
public long peakFront(){
return queueArr[front];
}
//ÅжÏÊÇ·ñΪ¿Õ
public boolean isEmpty(){
return nItems == 0;
}
//ÅжÏÊÇ·ñÒÑÂú
public boolean isFull(){
return nItems == maxSize;
}
//·µ»Ø¶ÓÁÐÖÐÔªËØµÄ¸öÊý
public int size(){
return nItems;
}
public void print(){
for(int i =
Ïà¹ØÎĵµ£º
JavaỊ̈߳ºÐÂÌØÕ÷-Ëø£¨ÉÏ£©
ÔÚJava5ÖУ¬×¨ÃÅÌṩÁËËø¶ÔÏó£¬ÀûÓÃËø¿ÉÒÔ·½±ãµÄʵÏÖ×ÊÔ´µÄ·âËø£¬ÓÃÀ´¿ØÖƶԾºÕù×ÊÔ´²¢·¢·ÃÎʵĿØÖÆ£¬ÕâЩÄÚÈÝÖ÷Òª¼¯ÖÐÔÚjava.util.concurrent.locks °üÏÂÃæ£¬ÀïÃæÓÐÈý¸öÖØÒªµÄ½Ó¿ÚCondition¡¢Lock¡¢ReadWriteLock¡£
Condition
Condition ½« Object ¼àÊÓÆ÷·½·¨£¨wait¡¢notify ......
JavaỊ̈߳ºÐÂÌØÕ÷-ÐźÅÁ¿
JavaµÄÐźÅÁ¿Êµ¼ÊÉÏÊÇÒ»¸ö¹¦ÄÜÍê±ÏµÄ¼ÆÊýÆ÷£¬¶Ô¿ØÖÆÒ»¶¨×ÊÔ´µÄÏû·ÑÓë»ØÊÕÓÐןÜÖØÒªµÄÒâÒ壬ÐźÅÁ¿³£³£ÓÃÓÚ¶àÏ̵߳ĴúÂëÖУ¬²¢ÄÜ¼à¿ØÓжàÉÙÊýÄ¿µÄÏ̵߳ȴý»ñÈ¡×ÊÔ´£¬²¢ÇÒͨ¹ýÐźÅÁ¿¿ÉÒÔµÃÖª¿ÉÓÃ×ÊÔ´µÄÊýÄ¿µÈµÈ£¬ÕâÀï×ÜÊÇÔÚÇ¿µ÷“ÊýÄ¿”¶þ×Ö£¬µ«²»ÄÜÖ¸³öÀ´ÓÐÄÄЩÔڵȴý£¬ÄÄЩ×ÊÔ ......
JavaỊ̈߳ºÐÂÌØÕ÷-×èÈû¶ÓÁÐ
×èÈû¶ÓÁÐÊÇJava5Ïß³ÌÐÂÌØÕ÷ÖеÄÄÚÈÝ£¬Java¶¨ÒåÁË×èÈû¶ÓÁеĽӿÚjava.util.concurrent.BlockingQueue£¬×èÈû¶ÓÁеĸÅÄîÊÇ£¬Ò»¸öÖ¸¶¨³¤¶ÈµÄ¶ÓÁУ¬Èç¹û¶ÓÁÐÂúÁË£¬Ìí¼ÓÐÂÔªËØµÄ²Ù×÷»á±»×èÈûµÈ´ý£¬Ö±µ½ÓпÕλΪֹ¡£Í¬Ñù£¬µ±¶ÓÁÐΪ¿Õʱºò£¬ÇëÇó¶ÓÁÐÔªËØµÄ²Ù×÷ͬÑù»á×èÈûµÈ´ý£¬Ö±µ½ÓпÉÓÃÔªËØÎª ......
JavaỊ̈߳ºÐÂÌØÕ÷-Ìõ¼þ±äÁ¿
Ìõ¼þ±äÁ¿ÊÇJava5Ïß³ÌÖкÜÖØÒªµÄÒ»¸ö¸ÅÄ¹ËÃû˼Ò壬Ìõ¼þ±äÁ¿¾ÍÊDZíʾÌõ¼þµÄÒ»ÖÖ±äÁ¿¡£µ«ÊDZØÐë˵Ã÷£¬ÕâÀïµÄÌõ¼þÊÇûÓÐʵ¼Êº¬ÒåµÄ£¬½ö½öÊǸö±ê¼Ç¶øÒÑ£¬²¢ÇÒÌõ¼þµÄº¬ÒåÍùÍùͨ¹ý´úÂëÀ´¸³ÓèÆäº¬Òå¡£
ÕâÀïµÄÌõ¼þºÍÆÕͨÒâÒåÉϵÄÌõ¼þ±í´ïʽÓÐ×ÅÌìÈÀÖ®±ð¡£
Ìõ¼þ±äÁ¿¶¼ÊµÏÖÁË ......
ÊäÈëÊä³öÁ÷
ÔÚJavaÖУ¬ÎÒÃǰÑÄܹ»¶Áȡһ¸ö×Ö½ÚÐòÁеĶÔÏó³Æ×÷Ò»¸öÊäÈëÁ÷;¶øÎÒÃǰѹ»Ð´Ò»¸ö×Ö½ÚÐòÁгÆ×÷Ò»¸öÊä³öÁ÷¡£ËüÃÇ·Ö±ðÓɳéÏóÀà InputStreamºÍOutputStreamÀà±íʾ¡£ÒòÎªÃæÏò×Ö½ÚµÄÁ÷²»·½±ãÓÃÀ´´¦Àí´æ´¢ÎªUnicode£¨Ã¿¸ö×Ö·ûʹÓÃÁ½¸ö×Ö½Ú)µÄÐÅÏ¢¡£ËùÒÔJavaÒýÈëÁËÓÃÀ´´¦ÀíUnicode×Ö·ûµÄÀà²ã´Î£¬ÕâЩÀàÅÉÉú×Ô³éÏóÀàReade ......