Question: C# Bubble Sort, Insertion Sort, and Selection Sort. PLEASE follow instructions specifically. I need three blocks of code converted into EACH a Bubble Sort, Insertion

C# Bubble Sort, Insertion Sort, and Selection Sort. PLEASE follow instructions specifically. I need three blocks of code converted into EACH a Bubble Sort, Insertion Sort, and Selection Sort. Sorted by Title, Author, and ID # These lines italic and are named

public string ToString_Title()

public string ToString_Author()

public string ToString_ID()

...and underneath the block of code you should see this statement to verify it needs to be changed.

//CHANGE THIS INTO ONE OF THE THREE SORTS

This is for a library project, the code is completed and working.

This is what must be done according to the instructions : "One for sorting by title, one for sorting by author and one for sorting by idnum. Each sort must use a different process, i.e. one uses a bubble sort, one uses a selection sort and one uses an insertion sort"

Please just convert those three lines of code into each example of the sorts I stated above. Below is the code

using System;

using System.Collections.Generic;

using System.Linq;

namespace MainClass

{

//class "Mainclass" which conatain the variables, method etc.

class MainClass

{

//main functon to start the execution

public static void Main (string[] args)

{

//object creation for the class

Library lib = new Library("Library 1");

//to insert the book

lib.AddBook ("C# programming", "Gesick", 4);

lib.AddBook ("java programming", "Roth", 2);

lib.AddBook ("C++ programming", "Franklin", 1);

lib.AddBook ("unity programming", "Preston", 3);

lib.AddBook ("graphics & multimedia", "Chastine", 5);

printMenu ();

string p = Console.ReadLine ();

p = p.ToUpper ();

char pick = p [0];

while (pick!='Q') {

switch (pick) {

case 'A':

Console.WriteLine (" Insert the name of the title for the new book .");

string tem = Console.ReadLine();

int yy = Library.Search_pro(tem);

if(yy == -1)

{

Console.WriteLine ("Insert the name of the author for the new book.");

string aa = Console.ReadLine();

int num = Library.GetBook_Count();

lib.AddBook (tem, aa, num + 1);

Console.WriteLine("The book is successfully inserted!");

}

else

{

Console.WriteLine ("This book title exists int the list!");

break;

}

break;

case 'S':

Console.WriteLine ("Type the name of the book title to be search: ");

string str = Console.ReadLine ();

int output = Library.Search_pro(str);

if(output == -1)

{

Console.WriteLine("This book is not found.");

}

break;

case 'D':

Console.WriteLine(lib.ToString_Title());

break;

case 'E':

Console.WriteLine(lib.ToString_Author());

break;

case 'F':

Console.WriteLine(lib.ToString_ID());

break;

case 'R':

Console.WriteLine ("Type a name book title to be remove: ");

string y = Console.ReadLine ();

Library.Remove_Book(y);

Console.WriteLine ("The book is successfully removed!");

break;

default:

Console.WriteLine (" Invalid choice, please re-enter the choice");

break;

}

printMenu ();

p = Console.ReadLine ();

p = p.ToUpper ();

pick = p [0];

}

Console.WriteLine ("good bye");

}

//this method is used to print the content of choice

public static void printMenu ()

{

Console.WriteLine (" Select one of the following: " +

" A to add a book to the library " +

" S to search for a book by title " +

" D to display the contents of the library, alphabetically by title " +

" E to display the contents of the library, alphabetically by author " +

" F to display the contents of the library, in ascending order by id num " +

" R to remove a book from the library " +

" Q to quit this program ");

Console.Write ("Enter the choice here: ");

}

}

//class "Library" which conatain the variables, method etc.

public class Library

{

private string lib_name;

static List bookTit = new List();

public Library(string ss)

{

lib_name = ss;

}

//This function is used to insert the book

public void AddBook(string tit, string ss, int id)

{

Book book = new Book (tit, ss, id);

bookTit.Add (book);

}

//this the override method

public override string ToString()

{

string wor = "";

foreach (Book zss in bookTit) {

wor += zss.ToString ();

wor += " ";

}

return wor;

}

//This function is used to place the title name

public string ToString_Title()

{

string wor = "";

var sort_List = bookTit.OrderBy(x => x.get_Tit()).ToList();

foreach (Book zss in sort_List) {

wor += zss.ToString ();

wor += " ";

}

return wor;

}

//CHANGE THIS INTO ONE OF THE THREE SORTS

//This function is used to place the Author name

public string ToString_Author()

{

string wor = "";

var sort_List = bookTit.OrderBy(x => x.get_Auth()).ToList();

foreach (Book zss in sort_List) {

wor += zss.ToString_print ();

wor += " ";

}

return wor;

}

//CHANGE THIS INTO ONE OF THE THREE SORTS

//This function is used to place the id number

public string ToString_ID()

{

string wor = "";

var sort_List = bookTit.OrderBy(x => x.get_id()).ToList();

foreach (Book zss in sort_List) {

wor += zss.ToString_print ();

wor += " ";

}

return wor;

}

//CHANGE THIS INTO ONE OF THE THREE SORTS

//This function is used to search the book

public static int Search_pro(string title)

{

for (int k=0; k<= bookTit.Count - 1; k++)

{

if(title == bookTit[k].ToString())

{

Console.WriteLine (bookTit[k].ToString_print());

return k;

}

}

return -1;

}

// this function is used to remove the book from the storage location

public static void Remove_Book(string title)

{

for (int k=0; k<= bookTit.Count - 1; k++)

{

if(title == bookTit[k].ToString())

{

bookTit.RemoveAt (k);

}

}

}

//This method is used to get the bookcount

public static int GetBook_Count()

{

return bookTit.Count;

}

}

//class "Mainclass" which conatain the variables, method etc.

public class Book

{

private string tit;

private string auth;

private int id_num;

//constructor

public Book(string aaa, string bbb, int ccc)

{

tit = aaa;

auth = bbb;

id_num = ccc;

}

//Thus function is used to get the title

public string get_Tit() {

return tit;

}

//Thus function is used to get the author

public string get_Auth() {

return auth;

}

//Thus function is used to get the id

public int get_id() {

return id_num;

}

//override method

public override string ToString()

{

return tit;

}

//print the string

public string ToString_print()

{

return tit + " by " + auth + " with ID " + id_num;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!