public void RemoveAt(String author) { AuthorLinkedListNode current = front; AuthorLinkedListNode beforecurrent = front; while (current.next != null) { String currentauthor = current.author; if (currentauthor.Equals(author)) { break; } beforecurrent = current; current = current.next; } if (current == front) { front = front.next; } beforecurrent.next = current.next; }
public ErrorCode Remove(string author, string title) { AuthorLinkedListNode authornode = authorList.FindAuthorNode(author); if (authornode == null) { return(ErrorCode.BookNotFound); } else { if (authorList.FindBookInAuthor(authornode, title)) { authorList.RemoveBookFromAuthor(authornode, title); Book.LinkedListNode front = authornode.collection.ReturnFront(); if (front == null) //if an author node have no book node { authorList.RemoveAt(author); } return(ErrorCode.OK); } return(ErrorCode.BookNotFound); } }
public bool FindBookInAuthor(AuthorLinkedListNode authornode, String title) { Book authorcollection = authornode.collection; if (authorcollection.Find(title)) { return(true); } return(false); }
public void print() { AuthorLinkedListNode current = front; while (current != null) { Console.WriteLine(); Console.WriteLine("Author: " + current.author); Book currentcollection = current.collection; currentcollection.Print(); current = current.next; } }
public ErrorCode Add(string author, string title, double price) { AuthorLinkedListNode authornode = authorList.FindAuthorNode(author); if (authornode == null) { authornode = authorList.AddSort(author); return(authorList.AddBookToAuthor(authornode, title, price)); } return(authorList.AddBookToAuthor(authornode, title, price)); }
public AuthorLinkedListNode FindAuthorNode(String name) { AuthorLinkedListNode current = front; while (current != null) { String currentauthor = current.author; if (currentauthor.Equals(name)) { return(current); } current = current.next; } return(null); }
public AuthorLinkedListNode AddSort(String name) { AuthorLinkedListNode current = front; AuthorLinkedListNode beforecurrent = front; AuthorLinkedListNode newNode = new AuthorLinkedListNode(name); if (front == null) { front = new AuthorLinkedListNode(name); return(front); } else { while (current.next != null && Compare(current.author, name) <= 0) { beforecurrent = current; current = current.next; } if (current == front && Compare(current.author, name) >= 0) { newNode.next = front; front = newNode; return(newNode); } if (Compare(current.author, name) >= 0) { beforecurrent.next = newNode; newNode.next = current; return(newNode); } newNode.next = current.next; current.next = newNode; return(newNode); } }
public void RemoveBookFromAuthor(AuthorLinkedListNode authornode, String title) { Book authorcollection = authornode.collection; authorcollection.RemoveAt(title); }
public ErrorCode AddBookToAuthor(AuthorLinkedListNode authornode, String title, double price) { Book authorcollection = authornode.collection; return(authorcollection.AddSort(title, price)); }