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

כתיבת פלט לתרגיל(רשימה C#)

Featured Replies

פורסם

להלן התרגיל:


List<int> lst = new List<int>();
lst.Insert(null, 10);
Node<int> pos = lst.Insert(null, -5);
lst.Insert(lst.GetFirst(), 17);
pos = lst.Insert(pos, 8);
lst.Insert(null, pos.GetInfo());
Console.WriteLine(lst);

מה שאני צריך זה שרטוט שמסביר שלב שלב את התרגיל.

תודה עומר.

פורסם

כבר אמרנו לך את זה בפעם הקודמת, אי אפשר לעזור בלי לדעת מה זה בכלל List ו-Node. אני מניח שהם חלק מאיזשהי חבילה שנתנו לכם, לא?

פורסם
  • מחבר

אין בעיה הנה המחלקות אני אישית יודע מה זה..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace listA
{

public class List<T>
{
Node<T> first;

public List()
{
this.first = null;
}
public bool IsEmpty()
{
return this.first == null;
}
public Node<T> GetFirst()
{
return this.first;
}
public Node<T> Insert(Node<T> pos, T x)
{
Node<T> temp = new Node<T>(x);
if (pos == null)//build first
{
temp.SetNext(this.first);
this.first = temp;
}
else//there is at list 1 node
{
temp.SetNext(pos.GetNext());
pos.SetNext(temp);
}
return temp;
}
public Node<T> Remove(Node<T> pos)
{
if (this.first == pos)
this.first = pos.GetNext();
else
{
Node<T> prevpos = this.GetFirst();
while (prevpos.GetNext() != pos)
prevpos = prevpos.GetNext();
prevpos.SetNext(pos.GetNext());
}
return pos.GetNext();
}
public override string ToString()
{
string str = "";
Node<T> pos = this.GetFirst();
while (pos != null)
{
str = str + pos.GetInfo().ToString() + ",";
pos = pos.GetNext();
}
return str;
}
}
}





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace listA
{
public class Node<T>
{
private T info;
private Node<T> next;

public Node(T x)//constructor
{
this.info = x;
this.next = null;
}
public Node(T x, Node<T> next)//constructor
{
this.info = x;
this.next = next;
}
public Node<T> GetNext()
{
return this.next;
}
public void SetNext(Node<T> next)
{
this.next = next;
}
public T GetInfo()
{
return this.info;
}
public void SetInfo(T x)
{
this.info = x;
}
public override string ToString()
{
return this.info.ToString();
}
}



}


פורסם

אוקי, סבבה. אני מניח שאתה יודע איך עובדת רשימה מקושרת, כן?

אתה הבנת איך עובדת הפונקציה insert? (מה אומר כל פרמטר, ומה קורה אם הפרמטר הראשון הוא null?)

פורסם
  • מחבר

סבבה לפי מה שאני יודע הפרמטר הראשון פוס מקבל חולייה גנרית הפוס למעשה מצביע על חוליה כלשהי שאחריו X הפרמטר השני יוצב הinfo של החולייה.

הפונקצייה לא בדיוק ברורה אפשר לקבל הסבר?

פורסם
  • מחבר

אין אפשרות פשוט לקבל הסבר?????!

פורסם

בכל מקרה, מה שהקוד עושה הוא:

List<int> lst = new List<int>();

ליצר רשימה של מספרים שלמים.

lst.Insert(null, 10);

דחוף לראש הרשימה את הערך 10.

Node<int> pos = lst.Insert(null, -5);

דחוף את הערך -5 לראש הרשימה (אחריו יגיע הערך 10, שהכנסנו קודם), והחזר את הכתובת של הצומת "-5" למשתנה pos.

lst.Insert(lst.GetFirst(), 17);

דחוף אחרי החולייה (Node) של "-5", למעשה אחרי החולייה השנייה, את הערך "17".

pos = lst.Insert(pos, 8);

הכנס אחרי החולייה (Node) של "-5", את הערך "8", והחזר את הכתובת של הצומת "8" למשתנה pos.

lst.Insert(null, pos.GetInfo());

הכנס לתחילת הרשימה את הערך "8".

Console.WriteLine(lst);

הדפס את הרישמה.

מקווה שעזרתי לך להכין את הסרטוט שאתה רוצה.

פורסם
  • מחבר

יאפ תודה רבה! :xyxthumbs: :xyxthumbs:

ארכיון

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

דיונים חדשים

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.