private static PhoneRecordNode Skip(PhoneRecordNode head, int skip)
        {
            var current = head;
            var depth   = 0;

            while (current.next != null && depth < skip)
            {
                current = current.next;
                depth++;
            }
            return(current);
        }
        private static IEnumerable <PhoneRecord> GetList(PhoneRecordNode head, int skip, int take)
        {
            var list = new List <PhoneRecord>();

            if (head == null)
            {
                return(list);
            }
            var startingNode = Skip(head, skip);

            list.AddRange(Take(startingNode, take));
            return(list);
        }
        private static List <PhoneRecord> Take(PhoneRecordNode current, int take)
        {
            var list = new List <PhoneRecord>();

            list.Add(current.record);

            while (current.next != null && list.Count < take)
            {
                current = current.next;
                list.Add(current.record);
            }
            return(list);
        }
        private static PhoneRecordNode AppendAlphabetically(PhoneRecordNode head, PhoneRecordNode node)
        {
            if (head == null || head.record == null)
            {
                head = node;
                return(head);
            }
            PhoneRecordNode current = head;

            if (string.CompareOrdinal(node.record.Name, current.record.Name) < 0)
            {
                node.next = current;
                head      = node;
                return(head);
            }

            while (current.next != null && string.CompareOrdinal(node.record.Name, current.next.record.Name) > -1)
            {
                current = current.next;
            }
            node.next    = current.next;
            current.next = node;
            return(head);
        }
 private static async Task UpdatePhoneBookAsync(string fileLocation, PhoneRecordNode phonebook)
 {
     using FileStream createStream = File.Create(fileLocation);
     await JsonSerializer.SerializeAsync(createStream, phonebook, options);
 }