예제 #1
0
        // Insert a cell after this one.
        public void InsertAfter(string newName)
        {
            PeopleCell newCell = new PeopleCell();

            newCell.Name = newName;
            newCell.Next = this.Next;
            this.Next    = newCell;
        }
예제 #2
0
 // Display the people in the list.
 private void DisplayList()
 {
     peopleListBox.Items.Clear();
     for (PeopleCell cell = TopCell; cell != null; cell = cell.Next)
     {
         peopleListBox.Items.Add(cell.Name);
     }
 }
예제 #3
0
        // Delete the cell after this one.
        public void DeleteAfter()
        {
            PeopleCell cell = this.Next;

            if (cell == null)
            {
                return;
            }
            this.Next = cell.Next;
            // free(cell);
        }
예제 #4
0
 // Return the cell before the indicated one.
 public PeopleCell FindCellBefore(string name)
 {
     for (PeopleCell cell = this; ; cell = cell.Next)
     {
         if (cell.Next == null)
         {
             return(null);
         }
         if (cell.Next.Name == name)
         {
             return(cell);
         }
     }
 }
예제 #5
0
        // Delete the indicate cell.
        public void Delete(string name)
        {
            // Find the cell before the one to delete.
            PeopleCell cell = this.FindCellBefore(name);

            if (cell == null)
            {
                throw new KeyNotFoundException("Item " +
                                               name + " not found in list.");
            }

            // Delete the target cell.
            cell.DeleteAfter();
        }
예제 #6
0
        // Insert a cell after the indicated one.
        public void InsertAfter(string afterName, string newName)
        {
            // Find the target cell.
            PeopleCell afterCell = FindCell(afterName);

            if (afterCell == null)
            {
                throw new KeyNotFoundException("Item " +
                                               afterName + " not found in list.");
            }

            // Insert the new name after the one we found.
            afterCell.InsertAfter(newName);
        }