עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

שאלה דחופה ב- Java - מחר בגרות

Featured Replies

פורסם

אני כבר יודע כמעט את כל החומר, אבל מאיזושהי סיבה כל הכיתה שלי מסתבכת עם השאלה הזאת ובנתיים אף אחד לא הצליח להשתמש רק בתור.

אני מקווה שתוכלו לעזור לי :)

[attachment deleted by admin]

פורסם

קודם תעתיק את התור שלך כדי לא להרוס את הקודם.

אחר כך, תוציא איבר מהתור ותכניס אותו לחדש. תיצור תור זמני ותוציא מהעותק ותכניס אליו רק כאלה שהם שונים מהמספר הראשון, תוך כדי ספירה כמה איברים היו שווים למספר הראשון. בסוף תכניס לתור החדר את המונה שלך.

תעשה ככה עד שהעותק יתרוקן.

יש לך בסך הכל תור אחד שאתה מקבל כINPUT, תור אחד כOUTPUT, ו2 תורים זמניים.

פורסם
  • מחבר

עריכה: לא משנה הסתדרתי! תודה רבה על העזרה :)

חבר שלי שלך לי את הקוד המלא


import unit4.collectionsLib.*;
import unit4.ioLib.IO;
public class TorbyCommency
{
public static void main(String args[])
{
Queue<Integer> tmp=new Queue<Integer>();
for(int i=0;i<10;i++)
tmp.insert((int)(Math.random()*10));
IO.println(tmp);
tmp=TorByCommen(tmp);
IO.println(tmp);

}
public static Queue<Integer> TorByCommen(Queue<Integer> q)
{
List<Integer> lst=new List<Integer>();
Queue<Integer> tmp=new Queue<Integer>();
Node<Integer> pos=null;
int holdNum,count=0;
tmp=newQueue(q);
while(tmp.isEmpty()==false)
pos=lst.insert(pos,tmp.remove());
pos=lst.getFirst();
while(lst.getFirst()!=null)
{
pos=lst.getFirst();
holdNum=pos.getInfo();
count++;
tmp.insert(holdNum);
pos=lst.remove(pos);
while(pos!=null)
{
if(pos.getInfo()==holdNum)
{
count++;
pos=lst.remove(pos);
}
else
pos=pos.getNext();
}
tmp.insert(count);
count=0;
}
return(tmp);
}
public static Queue<Integer> newQueue(Queue<Integer> q)
{
Queue<Integer> newq= new Queue<Integer>();
Queue<Integer> tempq= new Queue<Integer>();
int tmp;
while(q.isEmpty()==false)
{
tmp=q.remove();
newq.insert(tmp);
tempq.insert(tmp);
}
while(tempq.isEmpty()==false)
q.insert(tempq.remove());
return(newq);
}
}



לעזאזל, לא יוצא לי ואני כבר לא מצליח להתרכז.

בטח זה ממש מבולגן אבל זה מה שיצא לי עד עכשיו -

ד"א אני יודע שככה לא מעתיקים Queue אבל לא היה לי כח לכתוב קוד בשביל זה.

import unit4.collectionsLib.Queue;

import unit4.ioLib.IO;

public class test {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Queue<Integer> q=new Queue<Integer>();

q.insert(1);

q.insert(4);

q.insert(4);

q.insert(1);

q.insert(5);

q.insert(-9);

q.insert(1);

q.insert(-9);

q.insert(-9);

IO.print(q);

IO.println(commonQ(q));

}

public static Queue commonQ(Queue<Integer> q)

{

Queue<Integer> a=new Queue<Integer>();

Queue<Integer> q2=new Queue<Integer>();

Queue<Integer> help=new Queue<Integer>();

int tmp,count=0;

q2.insert(1);

q2.insert(4);

q2.insert(4);

q2.insert(1);

q2.insert(5);

q2.insert(-9);

q2.insert(1);

q2.insert(-9);

q2.insert(-9);

tmp=q2.remove();

a.insert(tmp);

count=count+1;

while (!q2.isEmpty())

{

if (tmp==q2.head())

{

count=count+1;

q2.remove();

}

else

{

help.insert(q2.remove());

}

if ((q2.isEmpty())&&(!help.isEmpty()))

{

q2=help;

a.insert(count);

count=1;

tmp=q2.remove();

}

}

return a;

}

}

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.