עבור לתוכן
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

פורסם

זה התוכנית הראשית:

package mypackage;

public class LongestKoter

{

public static void main(String[] args)

{

Tree t=new Tree(50);

for(int i = 0; i<20 ; i++)

insert(t,(int)((Math.random()*100)+1));

print(t);

}

public static void insert(Tree t, int x)

{

if(x<= t.getInfo() && t.getLeft()==null)

t.setLeft(new Tree(x));

if(x> t.getInfo() && t.getRight()==null)

t.setRight(new Tree(x));

if(x<= t.getInfo() && t.getLeft()!=null)

insert(t,x);

if(x> t.getInfo() && t.getRight()!=null)

insert(t,x);

}

public static void print(Tree t)

{

if(t.getLeft()!=null)

print(t.getLeft());

System.out.println(t.getInfo()+"/n");

if(t.getRight()!=null)

print(t.getRight());

}

}

וזה המחלקה TREE שאני יוצר ממנה עצמים

package mypackage;

public class Tree

{

private int info;

private Tree left;

private Tree right;

public Tree(int x)

{

this.info=x;

this.left=null;

this.right=null;

}

public Tree(int x, Tree left , Tree right)

{

this.info=x;

this.left=left;

this.right=right;

}

public int getInfo()

{

return(this.info);

}

public void setInfo(int x)

{

this.info=x;

}

public Tree getLeft()

{

return(this.left);

}

public Tree getRight()

{

return(this.right);

}

public void setLeft(Tree left)

{

this.left=left;

}

public void setRight(Tree right)

{

this.right=right;

}

}

תריצו קומפילציה תראו מה הבעיה..

פורסם

יש לך באג בפונקציה insert


public static void insert(Tree t, int x)
{
if(x<= t.getInfo() && t.getLeft()==null)
t.setLeft(new Tree(x));
if(x> t.getInfo() && t.getRight()==null)
t.setRight(new Tree(x));
if(x<= t.getInfo() && t.getLeft()!=null)
insert(t.getLedt(),x);
if(x> t.getInfo() && t.getRight()!=null)
insert(t.getRight(),x);
}

פורסם
  • מחבר

יש לך באג בפונקציה insert


public static void insert(Tree t, int x)
{
if(x<= t.getInfo() && t.getLeft()==null)
t.setLeft(new Tree(x));
if(x> t.getInfo() && t.getRight()==null)
t.setRight(new Tree(x));
if(x<= t.getInfo() && t.getLeft()!=null)
insert(t.getLedt(),x);
if(x> t.getInfo() && t.getRight()!=null)
insert(t.getRight(),x);
}

יש לך מושג מהי?

פורסם

מה שאני כתבתי זו הגירסה המתוקנת...

שים לב שמתי שיש עץ ימני/שמאלי קראת לפונקציה

insert(t,x);

במקום:

insert(t.getRight/Left(),x)

פורסם

אני הייתי רושם:

	if(x<= t.getInfo())
if(t.getLeft()==null)
t.setLeft(new Tree(x));
else
insert(t.getLeft(),x);
else
if(t.getRight()==null)
t.setRight(new Tree(x));
else
insert(t.getRight(),x);

ככה זה ברור יותר.

כל זה בהנחה שT הוא לא NULL. אתה יכול לזרוק אקספשיון אם הוא כן.

ארכיון

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

דיונים חדשים

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.