public ErrorCode AddSort(String title, double price) { LinkedListNode current = front; LinkedListNode beforecurrent = front; LinkedListNode newNode = new LinkedListNode(title, price); if (front == null) { front = new LinkedListNode(title, price); return(ErrorCode.OK); } else { while (current.GetNext() != null && Compare(current.GetTitle(), title) < 0) { beforecurrent = current; current = current.GetNext(); } if (current == front && Compare(current.GetTitle(), title) > 0) { newNode.SetNext(front); front = newNode; return(ErrorCode.OK); } if (Compare(current.GetTitle(), title) > 0) { beforecurrent.SetNext(newNode); newNode.SetNext(current); return(ErrorCode.OK); } if (Compare(current.GetTitle(), title) == 0) { return(ErrorCode.DuplicateBook); } newNode.SetNext(current.GetNext()); current.SetNext(newNode); return(ErrorCode.OK); } }
public void RemoveAt(String title) { LinkedListNode current = front; LinkedListNode beforecurrent = front; while (current != null) { String currenttitle = current.GetTitle(); if (currenttitle.Equals(title)) { break; } beforecurrent = current; current = current.GetNext(); } if (current == front) { front = front.GetNext(); } beforecurrent.SetNext(current.GetNext()); }
// Print out the book info (title, price). // Indenting this would be nice public void Print() { LinkedListNode current = front; while (current != null) { Console.WriteLine("Title: " + current.GetTitle()); Console.WriteLine("Price: $" + current.GetPrice()); current = current.GetNext(); } Console.WriteLine(); }
public bool Find(String title) { if (front == null) { return(false); } LinkedListNode current = front; while (current != null) { String currenttitle = current.GetTitle(); if (currenttitle.Equals(title)) { return(true); } current = current.GetNext(); } return(false); }