מדעי המחשב קיץ תשפ"ד 899271 פתרון מלא שאלה אחת בשפ...
מדעי המחשב קיץ תשפ"ד 899271 פתרון מלא שאלה אחת בשפת Java שאלון בגרות שאלה מספר 3 Java שאלה שלישית
public class BusStation{
private int num;
private int [] arr = new int [10]; // מי שעוצר בתחנה
private int amount=0;
public int[] getArr(){
return arr;
}
public boolean isStopping(int n)
{
for(int i=0; i<amount;i++)
{
if(arr[i]==n)
return true;
}
return false;
}
}
//3.ב
public static Node<Integer> allStation(BusStation [] buses)
{
Node<Integer> result = new Node<Integer>(0,null);
Node<Integer> p = result;
BusStation b = buses[0];
int [] arr = b.getArr();
for(int i=0; i<arr.length;i++)
{
boolean correct = true;
for(int j=1; j<buses.length; j++)
{
if( !buses[j].isStopping(arr[i]) )
correct =false;
}
if(correct==true)
{
Node<Integer> n = new Node<Integer>(arr[i]);
p.setNext(n);
p=p.getNext();
}
}
return result.getNext();
}