public static string FindByCreator(Gift gift, string creator) { for (int i = 0; i < gift.GetSize(); i++) { if (gift.GetCandy(i).Creator == creator) { return("That's our toy with creator " + creator + ":\n" + gift.GetCandy(i)); } } return("No one"); }
public static string FindByPrice(Gift gift, double price) { for (int i = 0; i < gift.GetSize(); i++) { if (gift.GetCandy(i).Price == price) { return("That's your toy with price " + price + ":\n" + gift.GetCandy(i)); } } return("No one"); }
public static string FindByWeight(Gift gift, double weight) { for (int i = 0; i < gift.GetSize(); i++) { if (gift.GetCandy(i).Weight == weight) { return("That's our toy with weight " + weight + ":\n" + gift.GetCandy(i)); } } return("No one"); }
public static void Bubble(Gift gift) { bool sorted = true; for (int i = gift.GetSize(); i > 0; i--) { for (int j = 0; j < i - 1; j++) { if (gift.GetCandy(j).Price > gift.GetCandy(j + 1).Price) { Candy tmp = gift.GetCandy(j); gift.ChangeCandy(gift.GetCandy(j + 1), j); gift.ChangeCandy(tmp, j + 1); sorted = false; } if (sorted) { break; } } } }
public static void Insert(Gift gift) { Candy temp; int j; for (int i = 0; i < gift.GetSize() - 1; i++) { if (gift.GetCandy(i).Price > gift.GetCandy(i + 1).Price) { temp = gift.GetCandy(i + 1); gift.ChangeCandy(gift.GetCandy(i), i + 1); j = i; while (j > 0 && temp.Price < gift.GetCandy(j - 1).Price) { gift.ChangeCandy(gift.GetCandy(j - 1), j); j--; } gift.ChangeCandy(temp, j); } } }