פורסם 2010 בפברואר 2115 שנים להלן התרגיל: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);מה שאני צריך זה שרטוט שמסביר שלב שלב את התרגיל.תודה עומר.
פורסם 2010 בפברואר 2115 שנים כבר אמרנו לך את זה בפעם הקודמת, אי אפשר לעזור בלי לדעת מה זה בכלל List ו-Node. אני מניח שהם חלק מאיזשהי חבילה שנתנו לכם, לא?
פורסם 2010 בפברואר 2115 שנים מחבר אין בעיה הנה המחלקות אני אישית יודע מה זה..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(); } }}
פורסם 2010 בפברואר 2115 שנים אוקי, סבבה. אני מניח שאתה יודע איך עובדת רשימה מקושרת, כן?אתה הבנת איך עובדת הפונקציה insert? (מה אומר כל פרמטר, ומה קורה אם הפרמטר הראשון הוא null?)
פורסם 2010 בפברואר 2115 שנים מחבר סבבה לפי מה שאני יודע הפרמטר הראשון פוס מקבל חולייה גנרית הפוס למעשה מצביע על חוליה כלשהי שאחריו X הפרמטר השני יוצב הinfo של החולייה.הפונקצייה לא בדיוק ברורה אפשר לקבל הסבר?
פורסם 2010 במרץ 115 שנים בכל מקרה, מה שהקוד עושה הוא: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);הדפס את הרישמה.מקווה שעזרתי לך להכין את הסרטוט שאתה רוצה.
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.