Here is the code. What does, I can not understand. Yes, the methods do serialization and back, but, for example, what the string List<ListNode> arr = new List<ListNode>(); does does List<ListNode> arr = new List<ListNode>(); ?
public void Serialize(FileStream s) { List<ListNode> arr = new List<ListNode>(); ListNode temp = new ListNode(); temp = Head; //transform nodes into List do { arr.Add(temp); temp = temp.Next; } while (temp != null); //write into file; data is modify for store index of .Random node using (StreamWriter w = new StreamWriter(s)) foreach (ListNode n in arr) w.WriteLine(n.Data.ToString() + ":" + arr.IndexOf(n.Rand).ToString()); } public void Deserialize(FileStream s) { List<ListNode> arr = new List<ListNode>(); ListNode temp = new ListNode(); Count = 0; Head = temp; string line; //try read file and create List of nodes try { using (StreamReader sr = new StreamReader(s)) { while ((line = sr.ReadLine()) != null) { if (!line.Equals("")) { Count++; temp.Data = line; ListNode next = new ListNode(); temp.Next = next; arr.Add(temp); next.Prev = temp; temp = next; } } } //declare Tail Tail = temp.Prev; Tail.Next = null; //return refs to Random nodes and restore Data foreach (ListNode n in arr) { n.Rand = arr[Convert.ToInt32(n.Data.Split(':')[1])]; n.Data = n.Data.Split(':')[0]; } }