/// <summary> /// Sorts the animals based on <paramref name="sortMethod"/> /// Fills the listview after sort /// </summary> public void SortAnimals(ListView listView, SortMethods sortMethod) { Comparer <Animal> comparer = null; switch (sortMethod) { case SortMethods.ID: comparer = new IDComparer(); break; case SortMethods.Name: comparer = new NameComparer(); break; case SortMethods.Age: comparer = new AgeComparer(); break; case SortMethods.Species: comparer = new SpeciesComparer(); break; default: return; } animals.Sort(comparer); FillAnimalsListView(listView); }
public TreeNode OrganizedTree(TreeNode tree) { var values = tree.InOrderTraversal().ToArray(); var sortedValues = SortMethods.BubbleSort(values).ToList(); var index = sortedValues.Count / 2; var root = new TreeNode(sortedValues.ElementAt(index)); while (sortedValues.Count != 0) { var j = sortedValues.Count / 2; var node = new TreeNode(sortedValues.ElementAt(index)); sortedValues.Remove(index); } if (sortedValues[index - 1] == sortedValues[index]) { root.right = new TreeNode(sortedValues[index - 1]); } else { } return(root); }
//Sort and return Inventory list #region Sort public List <Todo> Sort(SortMethods method, List <Todo> list) { switch (method) { //return Inventory ordered by ID case SortMethods.ID: { return(list.OrderBy(x => x.ID).ToList()); } //return Inventory ordered by ID reversed case SortMethods.IDReversed: { return(list.OrderBy(x => x.ID).Reverse().ToList()); } //return Inventory ordered by Importance(starred first) case SortMethods.StarredFirst: { return(list.OrderBy(x => x.IsStarred).Reverse().ToList()); } //return Inventory ordered by alphabetical ascending case SortMethods.AlphabeticalAscending: { return(list.OrderBy(x => x.Title).ToList()); } //return Inventory ordered by alphabetical descending case SortMethods.AlphabeticalDescending: { return(list.OrderBy(x => x.Title).Reverse().ToList()); } //return Inventory ordered by begin time case SortMethods.BeginTime: { return(list.OrderBy(x => x.BeginDateTime).ToList()); } //return Inventory ordered by end time case SortMethods.EndTime: { return(list.OrderBy(x => x.EndDateTime).ToList()); } //return Inventory ordered by creation date case SortMethods.CreationDate: { return(list.OrderBy(x => x.CreationDateTime).ToList()); } default: { return(null); } } }
public void SortByDescending() { //Arrange int[] inputArray = new int[] { 31, 41, 59, 26, 41, 58 }; int[] expectedArray = new int[] { 59, 58, 41, 41, 31, 26 }; //Act //Assert Assert.Equal(SortMethods.InsertionSortByDescending(inputArray), expectedArray); }
public void BubbleSortInOrder() { var startTime = DateTime.Now; var input = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; var result = SortMethods.BubbleSort(input); var endTime = DateTime.Now; Console.WriteLine($"Runtime: {(endTime - startTime).Milliseconds.ToString()}"); Assert.IsTrue(expected.SequenceEqual(result)); }
public void BubbleSortPartiallyOutOfOrder() { var startTime = DateTime.Now; var input = new int[] { 7, 2, 3, 4, 5, 6, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; var result = SortMethods.BubbleSort(input); var endTime = DateTime.Now; var evenNumbers = expected.Where(n => n % 2 == 0).ToList(); Console.WriteLine($"Runtime: {(endTime - startTime).Milliseconds.ToString()}"); Assert.IsTrue(expected.SequenceEqual(result)); }
/// <summary> /// Retrieve all albums from specified artist or genre /// </summary> public async Task<IMediaItemList<Album>> GetAlbums(int? artistId, int? genreId, AlbumFields fields, int? startIndex, int? endIndex, SortMethods? sortMethod, Orders? order) { List<JsonParam> parameters = new List<JsonParam>(); parameters.AddRange(ClientUtils.GetLimitsParameter(startIndex, endIndex)); parameters.AddRange(ClientUtils.GetSortOrderParameter(sortMethod, order)); parameters.Add(new JsonParam("properties", fields ?? DefaultAlbumProperties)); List<JsonParam> filters = new List<JsonParam>(); filters.AddRange(ClientUtils.GetOptionalParameter(artistId, "artistid")); filters.AddRange(ClientUtils.GetOptionalParameter(genreId, "genreid")); if (filters.Any()) { JsonParamObject filter = new JsonParamObject("filter", filters.ToArray()); parameters.Add(filter); } return await _client.PostAsync("AudioLibrary.GetAlbums", _serializer.Parse<XbmcItemList<Album>>, parameters.ToArray()); }
public void BubbleSortByMinElement_1234567_1273456() { int[][] array = new[] { new[] { 7, 1, 2 }, new[] { 3, 4, 5, 6 }, new[] { 0 } }; int[][] expectedArray = new[] { new[] { 3, 4, 5, 6 }, new[] { 7, 1, 2 }, new[] { 0 }, }; SortMethods.BubbleSortByMinElement(array); Assert.AreEqual(array, expectedArray); }
public void BubbleSortBySummary_1234567_1273456() { int[][] array = new[] { new[] { 1, 2 }, new[] { 3, 4, 5, 6 }, new[] { 7 } }; int[][] expectedArray = new[] { new[] { 3, 4, 5, 6 }, new[] { 7 }, new[] { 1, 2 } }; SortMethods.BubbleSortBySummary(array); Assert.AreEqual(array, expectedArray); }
private void LoadTodoList(FilterMethods filterMethod, SortMethods sortMethods) { currentInventory = todoManager.Filter(filterMethod); currentInventory = todoManager.Sort(sortMethods, currentInventory); if (TodoItemsStackPanel.Children.Count != 0) { TodoItemsStackPanel.Children.Clear(); } foreach (var item in currentInventory) { Itembar itembar = new Itembar(item); itembar.Click += new EventHandler(this.Itembar_Click); itembar.Remove += new EventHandler(this.Itembar_Remove); itembar.Update += new EventHandler(this.Itembar_Update); itembar.UpdateChosenTag += new EventHandler(this.Itembar_UpdateChosenTag); TodoItemsStackPanel.Children.Add(itembar); } }
private static string buildUrl(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int page = 1, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest) { if (AuthenticationKey == null || AuthenticationKey.Trim().Length == 0) { throw new NullReferenceException("API Key cannot be null!"); } if (page < 1) { page = 1; } if ((width <= 0 && height > 0) || (width > 0 && height <= 0)) { throw new ArgumentException("Both Width and height must be specified!"); } string toReturn = baseUrl + AuthenticationKey + "&method=" + method; switch (infolevel) { //case InfoLevels.Basic: case InfoLevels.IncludeCategory: toReturn += "&info_level=2"; break; case InfoLevels.IncludeCategoryCollectionAndGroup: toReturn += "&info_level=3"; break; } if (page > 1) { toReturn += "&page=" + page; } if (width > 0) { toReturn += "&width=" + width + "&height=" + height; } switch (op) { //case SizeOperators.Equal: case SizeOperators.Max: toReturn += "&operator=max"; break; case SizeOperators.Min: toReturn += "&operator=min"; break; } if (id > 0) { toReturn += "&id=" + id; } if (method == LookupMethods.search || method == LookupMethods.user) { toReturn += "&term=" + Uri.EscapeDataString(query); } switch (sortby) { case SortMethods.Favorites: toReturn += "&sort=favorites"; break; case SortMethods.Newest: toReturn += "&sort=newest"; break; case SortMethods.Rating: toReturn += "&sort=rating"; break; case SortMethods.Views: toReturn += "&sort=views"; break; } return(toReturn += "&check_last=1"); }
private static List <string> BuildUrls(LookupMethods method, InfoLevels infolevel = InfoLevels.Basic, int maxResults = 30, int width = 0, int height = 0, SizeOperators op = SizeOperators.Equal, int id = 0, string query = null, SortMethods sortby = SortMethods.Newest) { int maxPages = MaxResultsToPages(maxResults); List <string> toReturn = new List <string>(); for (int i = 0; i < maxPages; i++) { toReturn.Add(buildUrl(method, infolevel, i, width, height, op, id, query, sortby)); } return(toReturn); }
public static async Task <List <Wallpaper> > QueryAsync(LookupMethods method, InfoLevels level = InfoLevels.Basic, int maxResults = 30, Size?size = null, SizeOperators op = SizeOperators.Equal, int id = 0, string searchterm = null, SortMethods sortBy = SortMethods.Newest) { int width = 0; int height = 0; SizeToParams(size, out width, out height); List <string> urls = BuildUrls(method, level, maxResults, width, height, op, id, searchterm, sortBy); return(await Task.Run(() => { try { return Get(urls); } catch (Exception) { return null; } })); }
/// <summary> /// Retrieve all songs from specified artist /// </summary> public async Task<IMediaItemList<Song>> GetSongsForGenre(int genreId, SongFields fields, int? startIndex, int? endIndex, SortMethods? sortMethod, Orders? order) { return await GetSongs("genreid", genreId, fields, startIndex, endIndex, sortMethod, order); }
/// <summary> /// Sorts the List according to the method and direction you choose /// </summary> /// <param name="method">Which sorting algorith you would like to use</param> /// <param name="direction">Sort in Ascending or Descending order</param> public void sortList(SortMethods method, SortDirection direction) { // A List of 0 or 1 values has already been sorted if (valueList.Count < 2) { return; } switch (method) { case SortMethods.BubbleSort: this.bubbleSort(direction); break; case SortMethods.InsertionSort: this.insertionSort(direction); break; case SortMethods.SelectionSort: this.selectionSort(direction); break; case SortMethods.QuickSort: this.quickSort(direction, 0, -1); break; default: throw new Exception(method.ToString() + " has not been implemented yet"); break; } }
/// <summary> /// Retrieve all songs from specified artist /// </summary> public async Task<IMediaItemList<Song>> GetSongsForAlbum(int albumId, SongFields fields, int? startIndex, int? endIndex, SortMethods? sortMethod, Orders? order) { return await GetSongs("albumid", albumId, fields, startIndex, endIndex, sortMethod, order); }
protected async Task<IMediaItemList<Song>> GetSongs(string filterName, int id, SongFields fields, int? startIndex, int? endIndex, SortMethods? sortMethod, Orders? order) { List<JsonParam> parameters = new List<JsonParam>(); parameters.Add(new JsonParamObject("filter", new JsonParam(filterName, id))); parameters.AddRange(ClientUtils.GetLimitsParameter(startIndex, endIndex)); parameters.AddRange(ClientUtils.GetSortOrderParameter(sortMethod, order)); parameters.Add(new JsonParam("properties", fields ?? DefaultSongProperties)); return await _client.PostAsync("AudioLibrary.GetSongs", _serializer.Parse<XbmcItemList<Song>>, parameters.ToArray()); }
/// <summary> /// Sorts the animals based on <paramref name="sortMethod"/> /// Fills the listview after sort /// </summary> public void SortAnimals(SortMethods sortMethod) { Comparer <Animal> comparer = comparers[sortMethod]; Sort(comparer); }
/// <summary> /// Retrieve all artists /// </summary> /// <param name="albumArtistsOnly">Whether or not to include artists only appearing in compilations. If the parameter is not passed or is passed as null the GUI setting will be used</param> public async Task<IMediaItemList<Artist>> GetArtists(bool? albumArtistsOnly, int? genreId, ArtistFields fields, int? startIndex, int? endIndex, SortMethods? sortMethod, Orders? order) { List<JsonParam> parameters = new List<JsonParam>(); parameters.AddRange(ClientUtils.GetOptionalParameter(genreId, "genreid")); parameters.AddRange(ClientUtils.GetOptionalParameter(albumArtistsOnly, "albumartistsonly")); parameters.AddRange(ClientUtils.GetLimitsParameter(startIndex, endIndex)); parameters.Add(new JsonParam("properties", fields ?? DefaultArtistProperties)); parameters.AddRange(ClientUtils.GetLimitsParameter(startIndex, endIndex)); parameters.AddRange(ClientUtils.GetSortOrderParameter(sortMethod, order)); return await _client.PostAsync("AudioLibrary.GetArtists", t => _serializer.Parse<XbmcItemList<Artist>>(t), parameters.ToArray()); }