public MyLinkedListItem <T> FindItem(ulong itemNumber, MyLinkListSearchDirection direction)
        {
            MyLinkedListItem <T> retItem = null;

            switch (direction)
            {
            case MyLinkListSearchDirection.Ascending:
                retItem = FindItemAscending(itemNumber);
                break;

            case MyLinkListSearchDirection.Descending:
                retItem = FindItemDescending(itemNumber);
                break;
            }
            return(retItem);
        }
Beispiel #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            ulong itemNumber = 0;

            if (!ulong.TryParse(txtItemNumber.Text, out itemNumber))
            {
                MessageBox.Show("Please enter a valid non-negative number into the Item Number field.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtItemNumber.Focus();
                txtItemNumber.SelectAll();
                return;
            }

            MyLinkListSearchDirection searchType = (cmbSearchType.Text == "ASC") ? MyLinkListSearchDirection.Ascending : MyLinkListSearchDirection.Descending;
            string searchDataResult = "Unable to find entry.  Item Number is out of range.";

            if (bIntegerOrString)
            {
                if (IntegerLinkedList.IsEmpty)
                {
                    MessageBox.Show("Please load a file with integer data.", "Integer Data Empty", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                MyLinkedListItem <long> item = IntegerLinkedList.FindItem(itemNumber, searchType);
                if (item != null)
                {
                    searchDataResult = string.Format("Integer data found at position {0} from {1} of linked list.{2}Value: {3}", itemNumber,
                                                     (searchType == MyLinkListSearchDirection.Ascending) ? "front" : "back", Environment.NewLine, item.Value);
                }
            }
            else
            {
                if (StringLinkedList.IsEmpty)
                {
                    MessageBox.Show("Please load a file with string data.", "String Data Empty", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                MyLinkedListItem <string> item = StringLinkedList.FindItem(itemNumber, searchType);
                if (item != null)
                {
                    searchDataResult = string.Format("String data found at position {0} from {1} of linked list.{2}Value: {3}", itemNumber,
                                                     (searchType == MyLinkListSearchDirection.Ascending) ? "front" : "back", Environment.NewLine, item.Value);
                }
            }
            txtFoundData.Text = searchDataResult;
        }