السلام عليكم ورحمة الله وبركاته
لو سمحتم ممكن شرح هذي البرامج بالتفصيل ؟!
بليز ساعدوني
هذا البرنامج الاول
import java.io.*;
import java.util.*;
class pArrayQueue{
protected Object[] array;
protected int start,end;
protected boolean full;
public pArrayQueue(int maxsize){ //constructor
array = new Object[maxsize];
start = end = 0;
full = false;
}
public boolean isEmpty(){ //method
return ((start == end) && !full);
}
public void insert(Object o){ //method
if(!full)
array[start = (++start % array.length)] = o;
if(start == end)
full = true;
}
public Object remove(){
if(full)
full = false;
else if(isEmpty())
return null;
return array[end = (++end % array.length)];
}
}
class pArrayQueueTest{
public static void main(String[] args){
pArrayQueue q = new pArrayQueue(10);
Integer j = null;
int i;
System.out.println("starting...");
for(i=0;i<10;i++){
j = new Integer((int)(Math.random() * 100));
q.insert(j);
System.out.println("insert: " + j);
}
while(!q.isEmpty()){
System.out.println("remove: " + ((Integer)q.remove()));
}
System.out.println("Done ;-)");
}
}وهذا البرنامج الثاني
import java.util.Stack;
public class Stk {
public static void main(String args[]) {
Stack s = new Stack();
s.push("Java");
s.push("Forums");
s.push("and");
System.out.println("Next: " + s.peek());
s.push("Tips");
System.out.println(s.pop());
s.push(".");
int count = s.search("scd");
while (count != -1 && count > 1) {
s.pop();
count--;
}
System.out.println(s.pop());
System.out.println(s.empty());
}
}