2 תשובות
ניסיתי את זה הוא נתן לי אתה הקוד הזה:
public void addcontact(string name, string phone)
{
node<contact> pos;
contact c = new contact(name, phone);
node<contact> newcontact = new node<contact>(c);
pos = this.contacts;
if (pos == null)
{
this.contacts = newcontact;
return;
}
while (pos != null)
{
if (pos.data.name.compareto(name) > 0)
{
newcontact.next = pos;
this.contacts = newcontact;
return;
}
else if (pos.next == null || pos.next.data.name.compareto(name) > 0)
{
newcontact.next = pos.next;
pos.next = newcontact;
return;
}
pos = pos.next;
}
}
public void addcontact(string name, string phone)
{
node<contact> pos;
contact c = new contact(name, phone);
node<contact> newcontact = new node<contact>(c);
pos = this.contacts;
if (pos == null)
{
this.contacts = newcontact;
return;
}
while (pos != null)
{
if (pos.data.name.compareto(name) > 0)
{
newcontact.next = pos;
this.contacts = newcontact;
return;
}
else if (pos.next == null || pos.next.data.name.compareto(name) > 0)
{
newcontact.next = pos.next;
pos.next = newcontact;
return;
}
pos = pos.next;
}
}
אנונימי
תחפשי chat gpt בגוגל ותשאלי אותו מה לא בסדר בקוד בדרך כלל הוא נותן פתרונות
אנונימי
באותו הנושא: