// Bubble sort the given linked list public Node BubbleSort() { int swapped; Node ptr1; Node lptr = null; // Checking for empty list if (head == null) { return(null); } do { swapped = 0; ptr1 = head; while (ptr1.Next != lptr) { if (Double.Parse(ptr1.Data.Decimal) > Double.Parse(ptr1.Next.Data.Decimal)) { DeweyDecimal t = ptr1.Data; ptr1.Data = ptr1.Next.Data; ptr1.Next.Data = t; swapped = 1; } ptr1 = ptr1.Next; } lptr = ptr1; }while (swapped != 0); return(head); }
//Create File private void mnuNewFile_Click(object sender, EventArgs e) { using (SaveFileDialog dlg = new SaveFileDialog()) { dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; dlg.Title = "New FIle"; if (dlg.ShowDialog() == DialogResult.OK) { ExtensionMethods.storagePath = dlg.FileName; spaces = spaces.ReadFromDataStore(ExtensionMethods.storagePath); DeweyDecimal.Classification = DeweyDecimal.ReadToClassfication(); gbVirtualSotrageSpaces.Visible = true; gbEbooks.Visible = true; gbBookInfo.Visible = true; gbBookDetails.Visible = true; gbVirtualStorageSpaceInfo.Visible = true; mnuImportEbooks.Enabled = true; PopulateStorageSpaceList(); } } }
// Checks if the item exists in the list public bool Contains(DeweyDecimal value) { Node current = head; while (current != null) { if (current.Data == value) { return(true); } current = current.Next; } return(false); }
public void AddFirst(DeweyDecimal data) { Node newNode = new Node(data); if (head == null) { tail = newNode; } else { head.Previous = newNode; } head = newNode; Length++; }
// Finds the last node that contains the specified value public Node FindLast(DeweyDecimal value) { Node current = tail; while (current != null) { if (current.Data == value) { return(current); } current = current.Previous; } return(null); }
// Finds the node that contains the specified value public Node Find(DeweyDecimal value) { Node current = head; while (current != null) { if (current.Data == value) { return(current); } current = current.Next; } return(null); }
// AKA addLast public void Add(DeweyDecimal data) { Node newNode = new Node(data); if (tail == null) { head = newNode; } else { // Connect the final node newNode.Previous = tail; tail.Next = newNode; } // Set the new tail tail = newNode; Length++; }
public bool Remove(DeweyDecimal value) { Node current = head; while (current != null) { if (current.Data == value) { // End of the list if (current.Next == null) { // Remove the last item in the list tail = current.Previous; } else { current.Next.Previous = current.Previous; } // Start of the list if (current.Previous == null) { head = current.Next; } else { // Tie the nodes together current.Previous.Next = current.Next; } current = null; Length--; return(true); } current = current.Next; } return(false); }
public Node(DeweyDecimal data) { Data = data; }
public ImportBooks() { InitializeComponent(); spaces = spaces.ReadFromDataStore(storagePath); DeweyDecimal.Classification = DeweyDecimal.ReadToClassfication(); }