שאלון קיץ תשע"ט – 2019 מדעי המחשב – שאלון 899381שא...

שאלון קיץ תשע"ט – 2019 מדעי המחשב – שאלון 899381

שאלה מספר 5
סעיף א
פתרון ב-java:
public static int toNumber(Queue<Integer> q)
{
int result = 0;
int mul=1;

while(!q.isEmpty())
{
result = result + q.remove()*mul;
mul = mul *10;
}
return result;
}


פתרון ב-C# סי שארפ:
public static int ToNumber(Queue<int> q)
{
int result = 0;
int mul=1;

while(!q.IsEmpty())
{
result = result + q.Remove()*mul;
mul = mul *10;
}
return result;
}


סעיף ב
פתרון בשפת java:
public static int bigNumber(Node<Queue<Integer>> lst)
{
int max=0;
if( lst!=null )
{
Queue<Integer> q = lst.getValue();
max = toNumber(q);
}

lst = lst.getNext(); //קידום של המציע אחד קדימה

//סריקת שרשרת חוליות
while(lst!=null)
{
Queue<Integer> q = lst.getValue();
int temp= toNumber(q);
if(max<temp)
max=temp;

lst = lst.getNext();
}
return max;
}


פתרון בשפת C# סי שארפ:
public static int BigNumber(Node<Queue<int>> lst)
{
int max=0;
if( lst!=null )
{
Queue<int> q = lst.GetValue();
max = ToNumber(q);
}

lst = lst.GetNext(); //קידום של המציע אחד קדימה

//סריקת שרשרת חוליות
while(lst!=null)
{
Queue<int> q = lst.GetValue();
int temp= ToNumber(q);
if(max<temp)
max=temp;

lst = lst.GetNext();
}
return max;
}