KEMBAR78
Sort | PDF
0% found this document useful (0 votes)
11 views2 pages

Sort

The provided code is a sorting method for an array of 'Book' objects based on their genre, author, and name. It uses a nested loop structure to compare and swap books if they are not in the correct order. The sorting continues until all books are sorted according to the specified criteria.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Sort

The provided code is a sorting method for an array of 'Book' objects based on their genre, author, and name. It uses a nested loop structure to compare and swap books if they are not in the correct order. The sorting continues until all books are sorted according to the specified criteria.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public void Sort()

{
Book buf;
bool isSorted = false;
for (int i = 0; i < books.Length; i++)
{
for (int j = 0; j < books.Length-1; j++)
{
for (int symbol = 0; symbol < books[j].Janr.Length; symbol++)
{
if (books[j].Janr[symbol] > books[j + 1].Janr[symbol])
{
break;
}
else if (books[j].Janr[symbol] < books[j + 1].Janr[symbol])
{
buf = books[j];
books[j] = books[j + 1];
books[j + 1] = buf;

break;
}
else
{
if (books[j].Author[symbol] > books[j +
1].Author[symbol])
{
break;
}
else if (books[j].Author[symbol] < books[j +
1].Author[symbol])
{
buf = books[j];
books[j] = books[j + 1];
books[j + 1] = buf;

break;
}
else
{
if (books[j].Name[symbol] > books[j +
1].Name[symbol])
{
break;
}
else if (books[j].Name[symbol] < books[j +
1].Name[symbol])
{
buf = books[j];
books[j] = books[j + 1];
books[j + 1] = buf;

break;
}
}
}
}
}
}
}

You might also like